Created
June 27, 2015 11:01
-
-
Save andreasvirkus/a13bb9513414999763af to your computer and use it in GitHub Desktop.
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
//For the times that I need to know how far an element is from the top of the DOM, | |
//not the top of it’s parent, I use this helper function. | |
//Loops through all parent nodes of an element to get it's distance from the top of the document | |
function getDistanceFromTop(element) { | |
var yPos = 0; | |
while(element) { | |
yPos += (element.offsetTop); | |
element = element.offsetParent; | |
} | |
return yPos; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment