Create a gist now

Instantly share code, notes, and snippets.

Quick and dirty scroll-to-top bookmarklet with easing.
// 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