You read values off the DOM by constructing a JSON decoder.
See the target value for example use.
Get the offsetParent of the current element. Returns first argument if the current element is already the root; applies the second argument to the parent element if not.
To do traversals of the DOM, exploit that Elm allows recursive values.
Get the parent of an element.
Get the next sibling of an element.
Get the previous sibling of an element.
Find the ith child of an element.
Get the children of an element.
Decoders for reading sizing etc. properties off the DOM. All decoders return measurements in pixels.
Refer to, e.g., the Mozilla documentation for the precise semantics of these measurements. See also this stackoverflow answer.
Get the width of an element in pixels; underlying implementation
reads .offsetWidth.
Get the heigh of an element in pixels. Underlying implementation
reads .offsetHeight.
Get the left-offset of the element in the parent element in pixels.
Underlying implementation reads .offsetLeft.
Get the top-offset of the element in the parent element in pixels.
Underlying implementation reads .offsetTop.
Types for rectangles.
Approximation of the method getBoundingClientRect, based off this stackoverflow answer.
NB! This decoder is likely computationally expensive and may produce results
that differ slightly from getBoundingClientRect in browser-dependent ways.
(I don't get to call getBoundingClientRect directly from Elm without going native or using ports; my packages don't get to go native and I can find no solution with ports. So we do it like in the bad old days with an O(lg n) traversal of the DOM, only now through presumably expensive JSON decoders. It's 2007 forever, baby!)
Get the amount of left scroll of the element in pixels.
Underlying implementation reads .scrollLeft.
Get the amount of top scroll of the element in pixels.
Underlying implementation reads .scrollTop.
Get the class name(s) of an element.
Get the target DOM element of an event. You will usually start with this decoder. E.g., to make a button which when clicked emit an Action that carries the width of the button: