ryanve / verge

get viewport dimensions...detect elements in the viewport...trust in <!DOCTYPE html>
https://ryanve.dev/verge
MIT License
695 stars 51 forks source link

Element's offsetTop property? #6

Closed jmstout closed 10 years ago

jmstout commented 11 years ago

Was wondering if there's a way for getting an element's offsetTop property or its equivalent?

Enjoying this script, thanks for the hard work thus far. :+1:

ryanve commented 11 years ago

Thanks =) Do you mean relative to its .offsetParent like the native .offsetTop or relative to the document like jQuery.fn.offset? In some cases they are equal. You can adjust its rectangle coordinates to get the latter.

elem.offsetTop // => integer
verge.rectangle(elem).top + verge.scrollY(elem) // => like jQuery(elem).offset().top

See the jQuery source for reference. I had considered adding a verge.offset(elem) getter a while back.

jmstout commented 11 years ago

verge.rectangle(elem).top + verge.scrollY(elem)

Ah, thanks very much! This is exactly what I was looking for.

Is there any particular reason the .scrollY and .scrollX verge methods aren't documented in the readme? Just wondering if you'd like a PR for this...

ryanve commented 11 years ago

Sure thing—nice. Go for it if you want to. Otherwise I'll add them to the readme the next time I edit it. I guess I had originally debated the need for them, but they are here to stay and definitely should be in the docs.