-
-
Save cobalamin/6a5e009df6dcf53817030b4a4a226ecb to your computer and use it in GitHub Desktop.
Setting `scrollTop` doesn't work initially
This file contains 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
module ScrollTest exposing (..) | |
import Html.App as Html | |
import Html exposing (Html, Attribute, div, text, button) | |
import Html.Attributes exposing (style, property) | |
import Html.Events exposing (onClick) | |
import Json.Encode as Json | |
import String | |
main : Program Never | |
main = | |
Html.beginnerProgram | |
{ model = model | |
, view = view | |
, update = update | |
} | |
-- MODEL | |
type alias Model = | |
Bool | |
model : Model | |
model = | |
True | |
-- UPDATE | |
type Msg | |
= Toggle | |
update : Msg -> Model -> Model | |
update msg model = | |
case msg of | |
Toggle -> | |
not model | |
-- VIEW | |
view : Model -> Html Msg | |
view model = | |
div [] | |
[ button [ onClick Toggle ] [ text "Toggle" ] | |
, div (divStyle model) | |
[ text aLotOfText ] | |
, div [] [ text (toString model) ] | |
] | |
(=>) = | |
(,) | |
divStyle : Bool -> List (Attribute msg) | |
divStyle scrolled = | |
[ style | |
[ "border" => "1px solid black" | |
, "overflow" => "scroll" | |
, "width" => "100px" | |
, "height" => "100px" | |
] | |
] | |
++ if scrolled then | |
[ property "scrollTop" (Json.int 100) ] | |
else | |
[] | |
aLotOfText : String | |
aLotOfText = | |
String.repeat 20 "A lot of text! " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment