Last active
December 20, 2015 00:58
-
-
Save catdad/6045248 to your computer and use it in GitHub Desktop.
Scroll to element
This file contains hidden or 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
//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