Skip to content

Scrolling to position that always takes the same amount of time.

License

Notifications You must be signed in to change notification settings

WhileTruu/elm-smooth-scroll

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SmoothScroll

Scrolling to position that always takes the same amount of time.

Usage

The full working example lives in the example directory, which results in the demo linked above when built.

In order to scroll to the y offset of the browser viewport with the scrollTo function you first need a Config describing how the scrolling feels and how long it takes. A Config can be created using an easing function and a duration.

  • easing: Easing functions specify the rate of change of a parameter over time.

  • duration: The total duration of the scroll in milliseconds.

config : Config
config =
    createConfig Ease.outCubic 100

Provided we know the y we want to scroll to (the top of the page or the y value of an element found using Browser.Dom package for example), scrolling is as easy as passing the position to the scrollTo function along with the config.

scrollTo config 500

About

Scrolling to position that always takes the same amount of time.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages