Created
May 22, 2012 21:32
-
-
Save workmajj/2771742 to your computer and use it in GitHub Desktop.
Quick and dirty scroll-to-top bookmarklet with easing.
This file contains 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 characters
// full-source version: | |
javascript:(function(win) { | |
var STEP_SIZE = 200; // px | |
var DELAY = 20; // ms | |
var ease = function(scrollTop) { | |
if (scrollTop <= STEP_SIZE) { | |
win.scroll(0, 0); | |
return; | |
} | |
var newSt = scrollTop - STEP_SIZE; | |
win.scroll(0, newSt); | |
win.setTimeout(function() { | |
ease(newSt); | |
}, DELAY); | |
}; | |
win.setTimeout(function() { | |
ease(win.pageYOffset); | |
}, DELAY); | |
})(window); | |
// bookmarklet version: | |
javascript:(function(a){var d=function(b){if(200>=b)a.scroll(0,0);else{var c=b-200;a.scroll(0,c);a.setTimeout(function(){d(c)},20)}};a.setTimeout(function(){d(a.pageYOffset)},20)})(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment