phollyer/elm-motion/2.0.0

NOTE: the latest version is 3.0.4

Anim.Builder

Shared builder types and settings for animations.

Most app code will use the engine and property modules directly.

This module contains shared types and global builder settings.

Types

type alias AnimBuilder eng =
AnimBuilder eng

Base builder type for animations.

f : AnimBuilder eng -> AnimBuilder eng

The eng type parameter is a phantom type used to optionally constrain builder functions to specific engines or capabilities.

📖 See Engine Capabilities for details.

Engine Capability Types

Use these to constrain a builder function to one specific Engine.

type alias ForKeyframe =
ForKeyframe

Builder type for Keyframe builders.

f : AnimBuilder ForKeyframe -> AnimBuilder ForKeyframe
type alias ForSub =
ForSub

Builder type for Sub builders.

f : AnimBuilder ForSub -> AnimBuilder ForSub
type alias ForTransition =
ForTransition

Builder type for Transition builders.

f : AnimBuilder ForTransition -> AnimBuilder ForTransition
type alias ForWAAPI =
ForWAAPI

Builder type for WAAPI builders.

f : AnimBuilder ForWAAPI -> AnimBuilder ForWAAPI
type alias ForScroll =
ForScroll

Builder type for ScrollTimeline builders.

f : AnimBuilder ForScroll -> AnimBuilder ForScroll
type alias ForView =
ForView

Builder type for ViewTimeline builders.

f : AnimBuilder ForView -> AnimBuilder ForView

Builder Settings

All the engines expose their own equivalents of these functions that are engine-specific, these are the engine-agnostic versions. Use these when you are writing builder functions that should work across engines, or when you don't want to commit to a specific engine.

Timing

These settings are for Document timeline engines: Keyframe, Sub, Transition, and WAAPI. They make no sense when applied to Scroll and View timelines, and will raise a type error if used in builders for those engines.

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

Set the global delay for all animations in a Document timeline builder.

introAnim : AnimBuilder { eng | withTiming : () } -> AnimBuilder { eng | withTiming : () }
introAnim =
    delay 500
        >> fadeInHeader
        >> slideInSidebar
        >> fadeInContent
Int
-> AnimBuilder { eng | withTiming : () }
-> AnimBuilder { eng | withTiming : () }

Set the global duration for all animations in a Document timeline builder.

introAnim : AnimBuilder { eng | withTiming : () } -> AnimBuilder { eng | withTiming : () }
introAnim =
    duration 500
        >> fadeInHeader
        >> slideInSidebar
        >> fadeInContent
Float
-> AnimBuilder { eng | withTiming : () }
-> AnimBuilder { eng | withTiming : () }

Set the global speed for all animations in a Document timeline builder.

introAnim : AnimBuilder { eng | withTiming : () } -> AnimBuilder { eng | withTiming : () }
introAnim =
    speed 300
        >> slideDownHeader
        >> slideInSidebar
        >> slideUpContent

Playback

Int
-> AnimBuilder { eng | withIterations : () }
-> AnimBuilder { eng | withIterations : () }

Set how many times an animation should repeat.

notificationAttentionLoop : AnimBuilder { eng | withIterations : () } -> AnimBuilder { eng | withIterations : () }
notificationAttentionLoop =
    iterations 3
        >> pulseBadge
        >> nudgeBellIcon
AnimBuilder { eng | withAlternate : () }
-> AnimBuilder { eng | withAlternate : () }

Make an animation alternate direction on each iteration.

floatingCardLoop : AnimBuilder { eng | withAlternate : () } -> AnimBuilder { eng | withAlternate : () }
floatingCardLoop =
    iterations 4
        >> alternate
        >> liftCard
        >> glowCardBorder

alternate only has a visible effect when the animation runs more than once, so calling it when iterations is unset or 1 automatically bumps iterations to 2. An explicit iterations count (or loopForever) set before or after alternate is preserved.

Motion Behaviour

easing : Easing -> AnimBuilder eng -> AnimBuilder eng

Set the global easing function.

heroEntrance : AnimBuilder eng -> AnimBuilder eng
heroEntrance =
    easing EaseInOut
        >> fadeInHeroTitle
        >> slideInHeroArtwork
        >> revealPrimaryCta
Spring
-> AnimBuilder { eng | withSpring : () }
-> AnimBuilder { eng | withSpring : () }

Set the global spring.

draggableCardSettle : AnimBuilder { eng | withSpring : () } -> AnimBuilder { eng | withSpring : () }
draggableCardSettle =
    spring Spring.wobbly
        >> settleCardPosition
        >> settleCardShadow

CSS Units

Set the CSS unit for properties that use length values.

This is useful when you want properties to render in units like rem, cqh or vw, for example, instead of px, the default.

📖 See the property docs and Responsive Animations for more details.

-> AnimBuilder { eng | withCssUnit : () }
-> AnimBuilder { eng | withCssUnit : () }

Set the default length unit for all length-bearing properties.

responsivePanelMotion : AnimBuilder { eng | withCssUnit : () } -> AnimBuilder { eng | withCssUnit : () }
responsivePanelMotion =
    cssUnit Unit.Vw
        >> slidePanelIn
        >> growPanelHeight
-> AnimBuilder { eng | withCssUnit : () }
-> AnimBuilder { eng | withCssUnit : () }

Set the default length unit for the X axis.

responsiveDrawerMotion : AnimBuilder { eng | withCssUnit : () } -> AnimBuilder { eng | withCssUnit : () }
responsiveDrawerMotion =
    cssUnitX Unit.Vw
        >> slideDrawerX
        >> alignDrawerLabelX
-> AnimBuilder { eng | withCssUnit : () }
-> AnimBuilder { eng | withCssUnit : () }

Set the default length unit for the Y axis.

responsiveSheetMotion : AnimBuilder { eng | withCssUnit : () } -> AnimBuilder { eng | withCssUnit : () }
responsiveSheetMotion =
    cssUnitY Unit.Vh
        >> slideSheetY
        >> alignSheetHeaderY
-> AnimBuilder { eng | withCssUnit : () }
-> AnimBuilder { eng | withCssUnit : () }

Set the default length unit for the Z axis.

layeredSceneMotion : AnimBuilder { eng | withCssUnit : () } -> AnimBuilder { eng | withCssUnit : () }
layeredSceneMotion =
    cssUnitZ Unit.Px
        >> pushSceneBackgroundBack
        >> bringFloatingCardForward
cssUnitWidth : Unit -> AnimBuilder eng -> AnimBuilder eng

Set the default length unit used for width values.

responsiveCardWidth : AnimBuilder { eng | withCssUnit : () } -> AnimBuilder { eng | withCssUnit : () }
responsiveCardWidth =
    cssUnitWidth Unit.Vw
        >> growCardWidth
        >> settleCardSpacing
cssUnitHeight : Unit -> AnimBuilder eng -> AnimBuilder eng

Set the default length unit used for height values.

responsivePanelHeight : AnimBuilder eng -> AnimBuilder eng
responsivePanelHeight =
    cssUnitHeight Unit.Vh
        >> expandPanelHeight
        >> alignPanelHeaderY