Is there an Elm equivalent to jQuery.offset?
In Elm 0.19, Browser.Dom.getElement
will return a (task returned) record Element
containing all the required information. Then you can do:
distFromTop : Element -> Int
distFromTop elementInfo =
elmentInfo.element.y - elementInfo.viewport.y
(Note that this distFromTop
may return a negative number if the viewport is currently displaying a portion of the page below your element.)
You can see a complete example of the mechanism Task
you need to do this in a function getImgPosition
in my Elbum project.
source to share
It looks like you want the y function in the Dom library . Please note that this kind of function is not clean (downward distance can vary), so you need to use a task to work with it. This adds a bit of cognitive overhead for the developer, but of course gives you the other assurances that Elm offers.
source to share