If I want how far my element is from the top of the screen in Elm, how do I do that?
In context, I'm trying to figure out how to tell if an element is out of view in Elm, and according to this, that's the first ingredient I would need to do so.
If I want how far my element is from the top of the screen in Elm, how do I do that?
In context, I'm trying to figure out how to tell if an element is out of view in Elm, and according to this, that's the first ingredient I would need to do so.
In Elm 0.19, Browser.Dom.getElement will return (a task that returns) an Element record containing all the info you need. Then you can do:
distFromTop : Element -> Int
distFromTop elementInfo =
elmentInfo.element.y - elementInfo.viewport.y
(Note that distFromTop may return a negative number if the viewport is currently showing a part of the page below your element.)
You can see a full example of the Task machinery you'll need to put around this in the getImgPosition function in my Elbum project.