Revisions
-
james2doyle revised this gist
Dec 16, 2014 . 1 changed file with 17 additions and 10 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 @@ -25,22 +25,29 @@ var requestAnimFrame = (function(){ })(); function scrollTo(to, callback, duration) { // because it's so fucking difficult to detect the scrolling element, just move them all function move(amount) { document.documentElement.scrollTop = amount; document.body.parentNode.scrollTop = amount; document.body.scrollTop = amount; } function position() { return document.documentElement.scrollTop || document.body.parentNode.scrollTop || document.body.scrollTop; } var start = position(), change = to - start, currentTime = 0, increment = 20; duration = (typeof(duration) === 'undefined') ? 500 : duration; var animateScroll = function() { // increment the time currentTime += increment; // find the value with the quadratic in-out easing function var val = Math.easeInOutQuad(currentTime, start, change, duration); // move the document.body move(val); // do the animation unless its over if (currentTime < duration) { requestAnimFrame(animateScroll); } else { if (callback && typeof(callback) === 'function') { -
james2doyle revised this gist
Dec 16, 2014 . 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 @@ -26,7 +26,7 @@ var requestAnimFrame = (function(){ function scrollTo(to, callback, duration) { // figure out if this is moz || IE because they use documentElement var doc = document.documentElement, start = doc.scrollTop, change = to - start, currentTime = 0, -
james2doyle revised this gist
Oct 18, 2013 . 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 @@ -26,7 +26,7 @@ var requestAnimFrame = (function(){ function scrollTo(to, callback, duration) { // figure out if this is moz || IE because they use documentElement var doc = (navigator.userAgent.indexOf('Firefox') != -1 || navigator.userAgent.indexOf('MSIE') != -1) ? document.documentElement : document.body, start = doc.scrollTop, change = to - start, currentTime = 0, -
james2doyle revised this gist
Oct 18, 2013 . 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 @@ -26,7 +26,7 @@ var requestAnimFrame = (function(){ function scrollTo(to, callback, duration) { // figure out if this is moz || IE because they use documentElement var doc = (navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Chrome') != -1) ? document.body : document.documentElement, start = doc.scrollTop, change = to - start, currentTime = 0, -
james2doyle revised this gist
Oct 17, 2013 . 1 changed file with 6 additions and 9 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 @@ -21,16 +21,13 @@ Math.inOutQuintic = function(t, b, c, d) { // requestAnimationFrame for Smart Animating http://goo.gl/sx5sts var requestAnimFrame = (function(){ return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function( callback ){ window.setTimeout(callback, 1000 / 60); }; })(); function scrollTo(to, callback, duration) { // figure out if this is moz || IE because they use documentElement var doc = (document.documentElement.classList.contains('mozilla-firefox') || document.documentElement.classList.contains('internet-explorer')) ? document.documentElement : document.body, start = doc.scrollTop, change = to - start, currentTime = 0, increment = 20; @@ -39,9 +36,9 @@ function scrollTo(to, callback, duration) { // increment the time currentTime += increment; // find the value with the quadratic in-out easing function var val = Math.easeInOutQuad(currentTime, start, change, duration); // move the document.body doc.scrollTop = val; // do the animation unless its over if(currentTime < duration) { requestAnimFrame(animateScroll); -
james2doyle revised this gist
Sep 17, 2013 . 1 changed file with 12 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 @@ -8,6 +8,17 @@ Math.easeInOutQuad = function (t, b, c, d) { return -c/2 * (t*(t-2) - 1) + b; }; Math.easeInCubic = function(t, b, c, d) { var tc = (t/=d)*t*t; return b+c*(tc); }; Math.inOutQuintic = function(t, b, c, d) { var ts = (t/=d)*t, tc = ts*t; return b+c*(6*tc*ts + -15*ts*ts + 10*tc); }; // requestAnimationFrame for Smart Animating http://goo.gl/sx5sts var requestAnimFrame = (function(){ return window.requestAnimationFrame || @@ -28,7 +39,7 @@ function scrollTo(to, callback, duration) { // increment the time currentTime += increment; // find the value with the quadratic in-out easing function var val = Math.inOutQuintic(currentTime, start, change, duration); // move the document.body document.body.scrollTop = val; // do the animation unless its over -
james2doyle revised this gist
Sep 17, 2013 . 1 changed file with 1 addition 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 @@ -8,6 +8,7 @@ Math.easeInOutQuad = function (t, b, c, d) { return -c/2 * (t*(t-2) - 1) + b; }; // requestAnimationFrame for Smart Animating http://goo.gl/sx5sts var requestAnimFrame = (function(){ return window.requestAnimationFrame || window.webkitRequestAnimationFrame || -
james2doyle revised this gist
Sep 17, 2013 . 1 changed file with 21 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,9 +1,5 @@ // easing functions http://goo.gl/5HLl8 Math.easeInOutQuad = function (t, b, c, d) { t /= d/2; if (t < 1) { return c/2*t*t + b @@ -12,23 +8,37 @@ Math.easeInOutQuad = function (t, b, c, d) { return -c/2 * (t*(t-2) - 1) + b; }; var requestAnimFrame = (function(){ return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function( callback ){ window.setTimeout(callback, 1000 / 60); }; })(); function scrollTo(to, callback, duration) { var start = document.body.scrollTop, change = to - start, currentTime = 0, increment = 20; duration = (typeof(duration) === 'undefined') ? 500: duration; var animateScroll = function(){ // increment the time currentTime += increment; // find the value with the quadratic in-out easing function var val = Math.easeInOutQuad(currentTime, start, change, duration); // move the document.body document.body.scrollTop = val; // do the animation unless its over if(currentTime < duration) { requestAnimFrame(animateScroll); } else { if (callback && typeof(callback) === 'function') { // the animation is done so lets callback callback(); } } }; animateScroll(); } -
james2doyle created this gist
Jun 2, 2013 .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,34 @@ // easing functions http://goo.gl/5HLl8 Math.easeInOutQuad = function (t, b, c, d) { //t = current time //b = start value //c = change in value //d = duration t /= d/2; if (t < 1) { return c/2*t*t + b } t--; return -c/2 * (t*(t-2) - 1) + b; }; function scrollTo(element, to, duration) { var start = element.scrollTop, change = to - start, currentTime = 0, increment = 20; var animateScroll = function(){ // increment the time currentTime += increment; // find the value with the quadratic in-out easing function var val = Math.easeInOutQuad(currentTime, start, change, duration); // move the element element.scrollTop = val; // do the animation unless its over if(currentTime < duration) { setTimeout(animateScroll, increment); } }; animateScroll(); } // scrollTo(document.body, 0, 500);