Skip to content

Instantly share code, notes, and snippets.

@catdad
Last active December 20, 2015 00:58
Show Gist options
  • Save catdad/6045248 to your computer and use it in GitHub Desktop.
Save catdad/6045248 to your computer and use it in GitHub Desktop.
Scroll to element
//scroll to element
function scrollTo(el, offset){
el.offsetParent && window.scroll(0, (function(){
var position = 0;
do { position += el.offsetTop; }
while (el = el.offsetParent);
return position - (+offset || 0);
})());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment