import Animator as Anim
import Html
import Html.Attributes
Anim.div
(Anim.transition (Anim.ms 200)
[ Anim.opacity <|
if model.visible then
1
else
0
]
)
[ Html.Attributes.id "my-element" ]
[ Html.text "Hello!" ]When transitioning to this state, start with a little extra velocity!
This takes a number from 0-1.
Choosing a nice duration can depend on:
So, start with a nice default and adjust it as you start to understand your specific needs.
Note — Here's a very good overview on animation durations and speeds.
Here are some premade animations.
There's nothing special about them, they're just convenient!
Check out how they're defined if you want to make your own.
You may want something more involved than a single step transition.
Here's an element that's blinking.
import Animator as Anim
import Html
import Html.Attributes
Anim.div
(Anim.loop
[ Anim.step (Anim.ms 200)
[ Anim.opacity 1
]
, Anim.wait (Anim.ms 200)
, Anim.step (Anim.ms 200)
[ Anim.opacity 0
]
]
)
[ Html.Attributes.id "my-element" ]
[ Html.text "Hello!" ]Animate an element on a specific timeline. Check out Animator.Timeline for more details.
This will
import Animator as Anim
import Html
import Html.Attributes
Anim.div
(Anim.onTimeline model.timeline
(\state ->
if state.open
[ Anim.opacity 1
]
else
[ Anim.opacity 0
, Anim.x -200
]
)
)
[ Html.Attributes.id "my-element" ]
[ Html.text "Hello!" ]