phollyer/elm-motion/1.0.0

NOTE: the latest version is 3.0.4

Scroll.Engine.Cmd

A simple fire-and-forget scroll command.

Choose this engine when you just want to trigger a scroll and move on.

📖 See Scroll Cmd Engine Documentation and Scroll Overview for details.

Use the Builder module to configure scroll targets.

Types

type alias ScrollBuilder =
ScrollBuilder

Builder type for scroll animations.

Trigger

scroll : msg -> (ScrollBuilder -> ScrollBuilder) -> Cmd msg

Start a scroll as a fire-and-forget Cmd.

import Scroll.Engine.Cmd as Cmd


type Msg
    = ScrollCompleted
    | ...


Cmd.scroll ScrollCompleted <|
    scrollToElement "target-section"

If you need progress, cancellation, or safe retriggering, use Scroll.Engine.Sub instead.

Timing

📖 See Timing for details.

delay : Int -> ScrollBuilder -> ScrollBuilder

Set the delay for all scrolls.

This will be inherited by all scrolls that don't define their own delay.

import Scroll.Builder as Scroll
import Scroll.Engine.Cmd as Cmd


scrollToElement : String -> ScrollBuilder -> ScrollBuilder
scrollToElement elementId =
    Cmd.delay 100
        >> Scroll.forDocument
        >> Scroll.toElement elementId
        >> Scroll.speed 200
        >> Scroll.build
duration : Int -> ScrollBuilder -> ScrollBuilder

Set the duration of all scrolls.

This will be inherited by all scrolls that don't define their own duration.

import Scroll.Builder as Scroll
import Scroll.Engine.Cmd as Cmd


scrollToElement : String -> ScrollBuilder -> ScrollBuilder
scrollToElement elementId =
    Cmd.duration 1000
        >> Scroll.forDocument
        >> Scroll.toElement elementId
        >> Scroll.build
speed : Float -> ScrollBuilder -> ScrollBuilder

Set the speed that scrolls should run at.

This will be inherited by all scrolls that don't define their own speed.

import Scroll.Builder as Scroll
import Scroll.Engine.Cmd as Cmd


scrollToElement : String -> ScrollBuilder -> ScrollBuilder
scrollToElement elementId =
    Cmd.speed 200
        >> Scroll.forDocument
        >> Scroll.toElement elementId
        >> Scroll.build

Easing

📖 See Easing for details.

easing : Easing -> ScrollBuilder -> ScrollBuilder

Set the easing function to be used by all scrolls.

This will be inherited by all scrolls that don't define their own easing.

import Motion.Easing exposing (Easing(..))
import Scroll.Builder as Scroll
import Scroll.Engine.Cmd as Cmd


scrollToElement : String -> ScrollBuilder -> ScrollBuilder
scrollToElement elementId =
    Cmd.easing BounceOut
        >> Scroll.forDocument
        >> Scroll.toElement elementId
        >> Scroll.speed 200
        >> Scroll.build