rl-king/elm-inview/1.0.1

NOTE: the latest version is 2.0.1

InView

Detect

Detect if an element is visible in the current viewport.

check : String -> State -> Maybe Bool

True if the element is in the current viewport.

check

checkWithOffset : String -> Float -> Float -> State -> Maybe Bool

True if the element is in the current viewport but with an x and y offset. A positive offset will make the viewport smaller and vice versa.

checkWithOffset

checkAlt : String -> State -> Maybe Bool

True if the element is in or above the current viewport.

checkAlt

checkAltWithOffset : String -> Float -> Float -> State -> Maybe Bool

True if the element is in or above the current viewport but with an x and y offset. A positive offset will make the viewport smaller and vice versa.

checkAltWithOffset

Definitions

type State

Keeps track of viewport position, viewport dimensions and element positions.

type Msg

A message type for the state to update.

Init

init : List String -> ( State, Cmd Msg )

Takes the list of element ids you want to keep track of.

Update

update : Msg -> State -> ( State, Cmd Msg )

Update viewport size and element positions.

updateViewportOffset : Float -> Float -> State -> State

Update current viewport x and y offset. Use this function to update the viewport scroll position.

Subscribes to browser resize events and recalculates element positions.

addElements : List String -> Cmd Msg

Add elements you'd like to be able to detect after you've initialized the state.