forget about jquery, this actually works:
[cc lang=”js” escaped=”true” width=”600″]
/* calculate distance of dom element from top of screen element (jquery.position().top fails) */
function cumulativeOffset(element) {
var top = 0, left = 0;
do {
top += element.offsetTop || 0;
left += element.offsetLeft || 0;
element = element.offsetParent;
} while(element);
return {
top: top,
left: left
};
};
[/cc]
thanks to http://stackoverflow.com/users/17964/eyelidlessness
(Method shamelessly stolen from PrototypeJS; code style, variable names and return value changed to protect the innocent)
liked this article?
- only together we can create a truly free world
- plz support dwaves to keep it up & running!
- (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
- really really hate advertisement
- contribute: whenever a solution was found, blog about it for others to find!
- talk about, recommend & link to this blog and articles
- thanks to all who contribute!