Here's code for an onScroll function that can be used just like an
Html.Events.onClick. Basically, you can always use a Decoder with
Html.Events.on to listen to HTML events this way:
type alias ScrollEvent =
{ scrollHeight : Int
, scrollPos : Int
, visibleHeight : Int
}
onScroll : (ScrollEvent -> msg) -> Html.Attribute msg
onScroll tagger =
Html.Events.on "scroll" (Decode.map tagger onScrollJsonParser)
onScrollJsonParser : Decode.Decoder ScrollEvent
onScrollJsonParser =
Decode.map3 ScrollEvent
(Decode.at ["target", "scrollHeight"] Decode.int)
(Decode.at ["target", "scrollTop"] Decode.int)
(Decode.at ["target", "clientHeight"] Decode.int)
On Friday, February 10, 2017 at 4:58:21 AM UTC-8, Rupert Smith wrote:
>
> I could use Dom.Scroll to get the y-offset of the body (
> http://package.elm-lang.org/packages/elm-lang/dom/1.1.1/Dom-Scroll),
> using its 'x' and 'y' tasks. The trouble is I don't know when the body may
> have been scrolled since this is a task and not a subscription.
>
> Is a subscription for this available somewhere? Or just write my own port
> it...
>
--
You received this message because you are subscribed to the Google Groups "Elm
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.