Revisions
-
Louis-Rémi Babé revised this gist
Aug 2, 2011 . 2 changed files with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,7 +19,7 @@ window.animLoop = function( render, element ) { // - setTimeout returns the actual timeout now = now && now > 1E4 ? now : +new Date; var deltaT = now - lastFrame; // do not render frame when deltaT is too high if ( deltaT < 160 ) { running = render( deltaT, lastFrame = now ); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ function animLoop( render, element ) { if ( running !== false ) { requestAnimationFrame( loop, element ); var deltaT = now - lastFrame; // do not render frame when deltaT is too high if ( deltaT < 160 ) { running = render( deltaT ); } -
Louis-Rémi Babé revised this gist
Aug 2, 2011 . 1 changed file with 15 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ var elem = document.getElementById("animatedElem"), left = 0, lastFrame = +new Date, timer; // Move the element on the right at ~600px/s timer = setInterval(function() { var now = +new Date, deltaT = now - lastFrame; elem.style.left = ( left += 10 * deltaT / 16 ) + "px"; lastFrame = now; // clear the timer at 400px to stop the animation if ( left > 400 ) { clearInterval( timer ); } }, 16); -
Louis-Rémi Babé revised this gist
Aug 2, 2011 . No changes.There are no files selected for viewing
-
Louis-Rémi Babé revised this gist
Aug 2, 2011 . 3 changed files with 21 additions and 35 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,20 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,15 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ function animLoop( render, element ) { var running, lastFrame = +new Date; function loop( now ) { // stop the loop if render returned false if ( running !== false ) { requestAnimationFrame( loop, element ); running = render( now - lastFrame ); lastFrame = now; } } loop( lastFrame ); } // Usage animLoop(function( deltaT ) { elem.style.left = ( left += 10 * deltaT / 16 ) + "px"; if ( left > 400 ) { return false; } // optional 2nd arg: elem containing the animation }, animWrapper ); -
Louis-Rémi Babé revised this gist
Aug 2, 2011 . 1 changed file with 11 additions and 16 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,20 +1,15 @@ var elem = document.getElementById("animatedElem"), left = 0, lastFrame = +new Date, timer; // Move the element on the right at ~600px/s timer = setInterval(function() { var now = +new Date, deltaT = now - lastFrame; elem.style.left = ( left += 10 * deltaT / 16 ) + "px"; lastFrame = now; // clear the timer at 400px to stop the animation if ( left > 400 ) { clearInterval( timer ); } }, 16); -
Louis-Rémi Babé revised this gist
Aug 2, 2011 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ // Cross browser, backward compatible solution (function( window, Date ) { // feature testing var raf = window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || @@ -27,7 +27,7 @@ window.animLoop = function( render, element ) { } loop(); }; })( window, Date ); // Usage animLoop(function( deltaT, now ) { -
Louis-Rémi Babé revised this gist
Aug 2, 2011 . 2 changed files with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,7 +20,7 @@ window.animLoop = function( render, element ) { now = now && now > 1E4 ? now : +new Date; var deltaT = now - lastFrame; // skip a frame when deltaT is too high if ( deltaT < 160 ) { running = render( deltaT, lastFrame = now ); } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ function animLoop( render, element ) { requestAnimationFrame( loop, element ); var deltaT = now - lastFrame; // skip a frame when deltaT is too high if ( deltaT < 160 ) { running = render( deltaT ); } lastFrame = now; -
Louis-Rémi Babé revised this gist
Aug 2, 2011 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,7 +18,11 @@ window.animLoop = function( render, element ) { // - Chrome 10 doesn't return it at all // - setTimeout returns the actual timeout now = now && now > 1E4 ? now : +new Date; var deltaT = now - lastFrame; // skip a frame when deltaT is too high if ( deltaT > 160 ) { running = render( deltaT, lastFrame = now ); } } } loop(); -
Louis-Rémi Babé revised this gist
Aug 1, 2011 . 1 changed file with 16 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ function animLoop( render, element ) { var running, lastFrame = +new Date; function loop( now ) { // stop the loop if render returned false if ( running !== false ) { requestAnimationFrame( loop, element ); var deltaT = now - lastFrame; // skip a frame when deltaT is too high if ( deltaT > 160 ) { running = render( deltaT ); } lastFrame = now; } } loop( lastFrame ); } -
Louis-Rémi Babé revised this gist
Aug 1, 2011 . 2 changed files with 14 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,14 +1,20 @@ function animLoop( render, element ) { var running; function loop() { // stop if previous render returned false if ( running !== false ) { requestAnimationFrame( loop, element ); running = render(); } } loop(); } // Usage animLoop(function() { elem.style.left = ( left += 10 ) + "px"; if ( left > 400 ) { return false; } // optional 2nd arg: elem containing the animation }, animWrapper ); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,12 +8,9 @@ function animLoop( render, element ) { lastFrame = now; } } loop( lastFrame ); } // Move the element on the right at ~600px/s animLoop(function( deltaT ) { elem.style.left = ( left += 10 * deltaT / 16 ) + "px"; -
Louis-Rémi Babé revised this gist
Aug 1, 2011 . 1 changed file with 2 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,10 +11,9 @@ function animLoop( render, element ) { loop( +new Date ); } // Updated example var elem = document.getElementById("animatedElem"), left = 0; // Move the element on the right at ~600px/s animLoop(function( deltaT ) { elem.style.left = ( left += 10 * deltaT / 16 ) + "px"; -
Louis-Rémi Babé revised this gist
Aug 1, 2011 . 2 changed files with 19 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ function animLoop( render, element ) { function loop( now ) { requestAnimationFrame( loop, element ); render( now ); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,13 +1,24 @@ function animLoop( render, element ) { var running, lastFrame = +new Date; function loop( now ) { // stop the loop if render returned false if ( running !== false ) { requestAnimationFrame( loop, element ); running = render( now - lastFrame ); lastFrame = now; } } loop( +new Date ); } // Example var elem = document.getElementById("animatedElem"), left = 0, timer; // Move the element on the right at ~600px/s animLoop(function( deltaT ) { elem.style.left = ( left += 10 * deltaT / 16 ) + "px"; if ( left > 400 ) { return false; } }); -
Louis-Rémi Babé revised this gist
Aug 1, 2011 . 1 changed file with 4 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,18 +14,19 @@ window.animLoop = function( render, element ) { raf( loop, element ) : // fallback to setTimeout setTimeout( loop, 16 ); // Make sure to use a valid time, since: // - Chrome 10 doesn't return it at all // - setTimeout returns the actual timeout now = now && now > 1E4 ? now : +new Date; running = render( now - lastFrame, lastFrame = now ); } } loop(); }; })(); // Usage animLoop(function( deltaT, now ) { // rendering code goes here // return false; will stop the loop ... -
Louis-Rémi Babé revised this gist
Aug 1, 2011 . 4 changed files with 18 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,13 +1,13 @@ function animLoop( render, element ){ function loop( now ) { requestAnimationFrame( loop, element ); render( now ); } loop( +new Date ); } // Usage animLoop(function( now ) { // rendering code goes here ... // optional 2nd arg: elem containing the animation This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ function animLoop( render, element ){ var lastFrame = +new Date; function loop( now ) { requestAnimationFrame( loop, element ); render( now - lastFrame ); } loop( +new Date ); } // Usage animLoop(function( deltaT ) { ... }, animWrapper ); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,7 @@ var raf = window.mozRequestAnimationFrame || window.oRequestAnimationFrame; window.animLoop = function( render, element ) { var running, lastFrame = +new Date; function loop( now ) { if ( running !== false ) { raf ? @@ -17,7 +17,7 @@ window.animLoop = function( render, element ) { // Make sure to always return a valid time, since: // - Chrome 10 doesn't return it at all // - setTimeout returns the actual timeout running = render( now = ( now && now > 1E4 ? now : +new Date ), now - lastFrame ); } } loop(); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,2 +0,0 @@ -
Louis-Rémi Babé revised this gist
Aug 1, 2011 . 1 changed file with 6 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,13 +14,13 @@ window.animLoop = function( render, element ) { raf( loop, element ) : // fallback to setTimeout setTimeout( loop, 16 ); // Make sure to always return a valid time, since: // - Chrome 10 doesn't return it at all // - setTimeout returns the actual timeout running = render( now && now > 1E4 ? now : +new Date ); } } loop(); }; })(); -
Louis-Rémi Babé revised this gist
Aug 1, 2011 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ // minified to 208B, to see if it was tweetable, but :-( (function(b,a){a="RequestAnimationFrame";a=b["moz"+a]||b["webkit"+a]||b["ms"+a]||b["o"+a];b.animLoop=function(b,f,e){function c(d){e!==!1&&(a?a(c,f):setTimeout(c,16),e=b(d&&d>1E4?d:+new Date))}c()}})(window); -
Louis-Rémi Babé revised this gist
Aug 1, 2011 . 1 changed file with 33 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ // Cross browser, backward compatible solution (function() { // feature testing var raf = window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame || window.oRequestAnimationFrame; window.animLoop = function( render, element ) { var running; function loop( now ) { if ( running !== false ) { raf ? raf( loop, element ) : // fallback to setTimeout setTimeout( loop, 16 ); // Make sure to always return a valid time, since: // - Chrome 10 doesn't return it at all // - setTimeout returns the actual timeout running = render( now && now > 1E4 ? now : +new Date ); } } loop(); }; })(); // Usage animLoop(function( now ) { // rendering code goes here // return false; will stop the loop ... // optional 2nd arg: elem containing the animation }, animWrapper ); -
Louis-Rémi Babé revised this gist
Jul 29, 2011 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,4 +9,6 @@ function animLoop( render, element ){ // Usage animLoop(function() { // rendering code goes here ... // optional 2nd arg: elem containing the animation }, animWrapper ); -
Louis-Rémi Babé revised this gist
Jul 29, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,4 +9,4 @@ function animLoop( render, element ){ // Usage animLoop(function() { // rendering code goes here }, document.getElementById("animationWrapper") ); -
Louis-Rémi Babé created this gist
Jul 29, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ function animLoop( render, element ){ function loop( now ) { requestAnimationFrame( loop, element ); render( now || +new Date ); } loop(); } // Usage animLoop(function() { // rendering code goes here });