|
@@ -7,14 +7,13 @@ function WebGLAnimation() {
|
|
|
let context = null;
|
|
|
let isAnimating = false;
|
|
|
let animationLoop = null;
|
|
|
+ let requestId = null;
|
|
|
|
|
|
function onAnimationFrame( time, frame ) {
|
|
|
|
|
|
- if ( isAnimating === false ) return;
|
|
|
-
|
|
|
animationLoop( time, frame );
|
|
|
|
|
|
- context.requestAnimationFrame( onAnimationFrame );
|
|
|
+ requestId = context.requestAnimationFrame( onAnimationFrame );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -25,7 +24,7 @@ function WebGLAnimation() {
|
|
|
if ( isAnimating === true ) return;
|
|
|
if ( animationLoop === null ) return;
|
|
|
|
|
|
- context.requestAnimationFrame( onAnimationFrame );
|
|
|
+ requestId = context.requestAnimationFrame( onAnimationFrame );
|
|
|
|
|
|
isAnimating = true;
|
|
|
|
|
@@ -33,6 +32,8 @@ function WebGLAnimation() {
|
|
|
|
|
|
stop: function () {
|
|
|
|
|
|
+ context.cancelAnimationFrame( requestId );
|
|
|
+
|
|
|
isAnimating = false;
|
|
|
|
|
|
},
|