phollyer/elm-motion/1.0.3

NOTE: the latest version is 3.0.4

Anim.Property.Custom

Animate any numeric CSS property not covered by the first-class property modules (Translate, Rotate, Scale etc.).

Default: 0

When no start value is configured, the default will be used.

Types

type alias Builder eng =
Builder eng

Builder type for custom property animations.

type alias AnimGroupName =
String

Type alias for the animation group name.

= BorderBottomLeftRadius Unit
| BorderBottomRightRadius Unit
| BorderBottomWidth Unit
| BorderLeftWidth Unit
| BorderRadius Unit
| BorderRightWidth Unit
| BorderTopLeftRadius Unit
| BorderTopRightRadius Unit
| BorderTopWidth Unit
| BorderWidth Unit
| Bottom Unit
| ColumnGap Unit
| ColumnWidth Unit
| FontSize Unit
| Gap Unit
| Inset Unit
| Left Unit
| LetterSpacing Unit
| LineHeight Unit
| Margin Unit
| MarginBottom Unit
| MarginLeft Unit
| MarginRight Unit
| MarginTop Unit
| MaxHeight Unit
| MaxWidth Unit
| MinHeight Unit
| MinWidth Unit
| OutlineOffset Unit
| OutlineWidth Unit
| Padding Unit
| PaddingBottom Unit
| PaddingLeft Unit
| PaddingRight Unit
| PaddingTop Unit
| Perspective Unit
| Right Unit
| RowGap Unit
| TabSize Unit
| TextIndent Unit
| Top Unit
| WordSpacing Unit
| FlexBasis Unit
| FlexGrow
| FlexShrink
| Cx
| Cy
| R
| Rx
| Ry
| StrokeDashOffset
| StrokeWidth
| Custom String String

A typed set of common numeric CSS properties with a custom escape hatch.

import Anim.Property.Custom as Property
import Anim.Unit exposing (Unit(..))




Property.begin (Property.LineHeight Em)
    >> Property.to 1.4 -- Animate to "1.4em"
    >> Property.end


Property.begin (Property.LineHeight Unitless)
    >> Property.to 1.4 -- Animate to "1.4" - 1.4x the element's font-size
    >> Property.end


Property.begin (Property.Custom "property-name" "unit")
    >> Property.to 32 -- Animate to "32unit"
    >> Property.end

Initialize

AnimGroupName
-> Float
-> AnimBuilder eng
-> AnimBuilder eng

Set the initial value for a custom CSS property.

Use this to initialize the property in your Engine's init function.

import Anim.Engine.* as Engine
import Anim.Property.Custom as Property
import Anim.Unit exposing (Unit(..))


init : ( Model, Cmd Msg )
init =
    ( { animState =
            Engine.init
                [ Property.init "box" (BorderRadius Px) 0 ]
      }
    , Cmd.none
    )

Build

begin : Property -> AnimBuilder eng -> Builder eng

Begin the animation configuration by turning an AnimBuilder into a custom property animation Builder.

import Anim.Unit exposing (Unit(..))


myAnimation : AnimBuilder eng -> AnimBuilder eng
myAnimation =
    Property.begin (Property.BorderRadius Px)
        >> Property.to 16
        >> Property.end
end : Builder eng -> AnimBuilder eng

Complete the animation configuration and return an AnimBuilder.

Configure

Start Value

When not set, the default will be used.

📖 See Start Values for details.

from : Float -> Builder eng -> Builder eng

Set the starting value.

End Value

📖 See End Values for details.

Absolute

to : Float -> Builder eng -> Builder eng

Set the target value.

Relative

Move by a delta instead of to a fixed value. The end value is current + delta, where current is the live animated value.

Only available on the Sub and WAAPI engines. Using these with any other engine results in a type error.

by :
Float
-> Builder { eng | withLiveDelta : () }
-> Builder { eng | withLiveDelta : () }

Move by a delta instead of to a fixed value.

import Anim.Property.Custom as Property
import Anim.Unit exposing (Unit(..))


myAnimation : AnimBuilder eng -> AnimBuilder eng
myAnimation =
    Property.begin (Property.BorderRadius Px)
        >> Property.by 4
        >> Property.end

Timing

📖 See Animation Timing for details.

Int
-> Builder { eng | withTiming : () }
-> Builder { eng | withTiming : () }

Set the delay (milliseconds) before the animation starts.

Int
-> Builder { eng | withTiming : () }
-> Builder { eng | withTiming : () }

Set the animation duration (milliseconds).

Float
-> Builder { eng | withTiming : () }
-> Builder { eng | withTiming : () }

Set the animation speed (units per second).

Easing

📖 See Easing for details.

easing : Easing -> Builder eng -> Builder eng

Set the easing function.

import Motion.Easing exposing (Easing(..))


Property.easing EaseInOut

Spring

📖 See Spring for details.

Spring
-> Builder { eng | withSpring : () }
-> Builder { eng | withSpring : () }

Drive this property with a spring.

import Motion.Spring as Spring


Property.spring Spring.wobbly

Clamping

Keep property values within a range you choose.

Values outside the range are clamped to the nearest boundary.

The range stays in effect for future animations until you Unclamp it:

update msg model =
    case msg of
        FontSizeChanged size ->
            let
                ( animState, cmd ) =
                    WAAPI.animate model.animState <|
                        Custom.begin Px)
                            >> Custom.clamp 12 32
                            >> Custom.end
            in
            ( { model | animState = animState }
            , cmd
            )

Useful if to values are coming from external sources; user input, slider values, or external data etc, and you need to keep them within a specific range.

Pairs well with by for relative animations where the delta could push the value outside the desired range.

Clamp

clamp : Float -> Float -> Builder eng -> Builder eng

Keep this CSS property's value within the min and max range.

If min > max, the values are swapped.

Unclamp

unclamp : Builder eng -> Builder eng

Remove the range for this CSS property. Does nothing if no range is set.

Snap

set : Float -> Builder eng -> Builder eng

Snap the value silently, cancelling any in-flight animation on this property.