Skip to content

Instantly share code, notes, and snippets.

@bloodyowl
Created June 19, 2012 15:23
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 bloodyowl/2954771 to your computer and use it in GitHub Desktop.
Save bloodyowl/2954771 to your computer and use it in GitHub Desktop.
smoothScroll
smoothScroll=function(b){var c="pageYOffset" in window?window.pageYOffset:document.documentElement.scrollTop,d=+new Date(),e=d+1000,f=document.height<(b.offsetTop+window.innerHeight)?document.height-window.innerHeight:b.offsetTop,s=f-c<0?true:false,g=setInterval(function(){var h=+new Date();if(h<=e){scrollTo(0,s?(c-(((h-d)/(e-d)*c)+f)):c+(h-d)/(e-d)*(f-c))}else{clearInterval(g)}},10)};
// smoothScroll(elementToReach)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment