Skip to content

Instantly share code, notes, and snippets.

@workmajj
Created May 22, 2012 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save workmajj/2771742 to your computer and use it in GitHub Desktop.
Save workmajj/2771742 to your computer and use it in GitHub Desktop.
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