linuss/smooth-scroll/1.1.0

SmoothScroll

Config

type alias Config =
{ offset : Int
, speed : Int
, easing : Easing
}

Configuration options for smooth scrolling. Has three options:

  • offset: The amount of space in pixels between the element to scroll to and the top of the viewport that is to remain after scrolling
  • speed: The higher this number, the faster the scrolling!
  • easing: The easing function to use. Check out the easing functions package for more information.
defaultConfig : Config
import SmoothScroll


defaultConfig : Config
defaultConfig =
    { offset = 12
    , speed = 200
    , easing = Ease.outQuint
    }

Scrolling

scrollTo : String -> Task Error (List ())

Scroll to the element with the given id, using the default configuration

import SmoothScroll


scrollTo "article"
scrollToWithOptions : Config -> String -> Task Error (List ())

Scroll to the element with the given id, using a custom configuration

import SmoothScroll exposing (defaultConfig)


scrollToWithOptions { defaultConfig | offset = 60 } "article"