Created
January 21, 2017 11:39
-
-
Save rundis/32df14aff206d61cf08c2d82e1bf508b to your computer and use it in GitHub Desktop.
elm - height of element in click handler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import DOM -- From debois/elm-dom | |
view state config = | |
div [ class "main" ] | |
[ div [ class "nav"] | |
[ button | |
[ myClickHandler state config] -- When clicking on the button I want to get the height of element with class "displayBlock" | |
[ text "MyButton" ] | |
div | |
[ class "displayNone" ] | |
[ div [ class "displayBlock" ] -- This is the element I need the height of. Works most of the time BUT ! | |
[ p [] [ text "Some text" ] | |
, p [] [ text "Some more text" ] | |
] | |
] | |
] | |
, div [ class "content" ] | |
[ div [ class "form" ] renderForm -- BUT Sometimes this is the element I get the height of and I'm struggling to understand why | |
, div [ class "whatever"] renderSomethingElse | |
] | |
] | |
myClickHandler state { toMsg } = | |
heightDecoder | |
|> Json.andThen | |
(\v -> Json.succeed <| toMsg <| updState state v) -- details left of but it's used in a larger context to initiate an animation | |
|> on "click" | |
-- This fella works as I would expect most of the times, but sometimes it get's the wrong element... what's UP I WONDER ? | |
heightDecoder : Json.Decoder Float | |
heightDecoder = | |
DOM.target <| | |
DOM.parentElement <| | |
DOM.nextSibling <| | |
DOM.childNode 0 <| | |
DOM.offsetHeight |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment