Skip to content

Instantly share code, notes, and snippets.

@jessta
Created October 4, 2016 03:03
Show Gist options
  • Save jessta/981e69e675363dda5ec0600cfcc78762 to your computer and use it in GitHub Desktop.
Save jessta/981e69e675363dda5ec0600cfcc78762 to your computer and use it in GitHub Desktop.
elm-style-animation example
module Main exposing (..)
import Animation exposing (px)
import Html exposing (Html, div, text)
import Html.App as App
import Html.Attributes exposing (style)
main =
App.program
{ init = init
, view = view
, update = update
, subscriptions = subscriptions
}
type alias Model =
{ style : Animation.State
}
type Msg
= Animate Animation.Msg
init : ( Model, Cmd Msg )
init =
( { style =
Animation.queue
[ Animation.to
[ Animation.left (px 300.0)
]
]
<|
Animation.style
[ Animation.left (px 0.0) ]
}
, Cmd.none
)
subscriptions : Model -> Sub Msg
subscriptions model =
Animation.subscription Animate [ model.style ]
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
Animate animMsg ->
( { model
| style = Animation.update animMsg model.style
}
, Cmd.none
)
view : Model -> Html Msg
view model =
div
(Animation.render model.style
++ [ style
[ ( "position", "absolute" )
, ( "border-style", "dotted" )
]
]
)
[ text "This is being Animated!" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment