Rerouted (regenerated, verified). Same repository and tag, but GitHub now builds the zip with different bytes, so it no longer matches the SHA-1 package.elm-lang.org recorded. The Lamdera package server serves a copy recovered from https://github.com/rl-king/elm-inview.
What we checked: Tag 2.0.0 is still on github.com/rl-king/elm-inview; its commit b3b7905f4365 is from 2020-06-22 19:39 UTC, before the version was published (2020-06-22 19:47 UTC); every file Elm uses matches a copy in a Lamdera package cache from 2021-02-13, from before the change; elm.json is byte-identical to package.elm-lang.org's; the exposed modules match docs.json; the zip's SHA-1 is not the published one (GitHub's zip no longer comes out byte for byte the same), so the contents were checked instead.
The Lamdera compiler uses this copy and prints a one-line notice saying so. elm itself fails to download this version.
Details · package.elm-lang.org's zip: https://github.com/rl-king/elm-inview/zipball/2.0.0/
Detect if an element is in the current viewport.
Since there is currently no way of listening to scroll events in Elm you'll have to hookup a port. Below is the bit of JS that gets you the scroll position and an example on how to set it all up.
port onScroll : ({x: Float, y: Float} -> msg) -> Sub msg
init : () -> ( Model, Cmd Msg )
init _ =
let
( inViewModel, inViewCmds ) =
InView.init ["1", "2", "3", "4", "5"]
in
( { inView = inViewModel }
, Cmd.map InViewMsg inViewCmds
)
subscriptions : Model -> Sub Msg
subscriptions model =
Sub.batch
[ InView.subscriptions InViewMsg model.inView
, onScroll OnScroll
]
type Msg
= OnScroll { x: Float, y: Float }
| InViewMsg InView.Msg
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
OnScroll offset ->
( { model | inView = InView.updateViewportOffset offset model.inView }
, Cmd.none
)
InViewMsg inViewMsg ->
let
( inView, inViewCmds ) =
InView.update InViewMsg inViewMsg model.inView
in
( { model | inView = inView }
, inViewCmds
)window.addEventListener("scroll", function() {
var offset = {x: window.pageXOffset, y: window.pageYOffset};
app.ports.onScroll.send(offset);
}, { passive: true });You might want to throttle or debounce this, listening to scroll events and getting positional information can cause some performance issues.