Skip to content

Commit

Permalink
Merge pull request #80 from stefan-hoeck/elem_scroll_info
Browse files Browse the repository at this point in the history
[ new ] extract scroll info for any Element
  • Loading branch information
stefan-hoeck authored Jun 21, 2024
2 parents def1daf + cc262f9 commit 6fa00f2
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Web/MVC/Event.idr
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,16 @@ export
inputInfo : InputEvent -> JSIO InputInfo
inputInfo e = changeInfo $ up e

export
elemScrollInfo : Element -> JSIO ScrollInfo
elemScrollInfo x =
[| MkScrollInfo (get x scrollTop) (scrollHeight x) (clientHeight x) |]

export
scrollInfo : Event -> JSIO ScrollInfo
scrollInfo e = do
Just et <- target e | Nothing => pure $ MkScrollInfo 0 0 0
case castTo Element et of
Nothing => pure $ MkScrollInfo 0 0 0
Just x =>
[| MkScrollInfo (get x scrollTop) (scrollHeight x) (clientHeight x) |]
Just et <- target e | Nothing => pure $ MkScrollInfo 0 0 0
maybe (pure $ MkScrollInfo 0 0 0) elemScrollInfo (castTo Element et)

export
wheelInfo : WheelEvent -> JSIO WheelInfo
Expand Down

0 comments on commit 6fa00f2

Please sign in to comment.