Vanilla JS Smooth Scroll
Easy to use!
Usage:
      
var smoothScroll = new scrollToSmooth('a', {
  targetAttribute: 'href',
  duration: 400,
  durationRelative: false,
  durationMin: false,
  durationMax: false,
  easing: 'easeOutCubic',
  onScrollStart: (data) => { console.log(data); },
  onScrollUpdate: (data) => { console.log(data); },
  onScrollEnd: (data) => { console.log(data); },
  fixedHeader: null
})
smoothScroll.init();
      
      

Options:

targetAttribute New!
Type: string
Default: 'href'

The attribute to determine the target element. Must be a valid selector!

duration
Type: Number
Default: 400

Scroll time in milliseconds

durationRelative New!
Type: boolean|number
Default: false

Used to calculate the duration based on the amount of pixels to scroll.
Use true to calculate by 1000px or a number to calculate by that.

durationMin New!
Type: number
Default: null

minimum duration time in ms

durationMax New!
Type: number
Default: null

maximum duration time in ms

easing
Type: string
Default: linear

Easing function used for scrolling.
Available Easings:

  • linear
  • easeInQuad
  • easeOutQuad
  • easeInOutQuad
  • easeInCubic
  • easeOutCubic
  • easeInOutCubic
  • easeInQuart
  • easeOutQuart
  • easeInOutQuart
  • easeInQuint
  • easeOutQuint
  • easeInOutQuint
  • easeInSine
  • easeOutSine
  • easeInOutSine
  • easeInExpo
  • easeOutExpo
  • easeInOutExpo
  • easeInCirc
  • easeOutCirc
  • easeInOutCirc
  • easeInElastic
  • easeOutElastic
  • easeInOutElastic
  • easeInBack
  • easeOutBack
  • easeInOutBack
  • easeInBounce
  • easeOutBounce
  • easeInOutBounce

onScrollStart New!
Type: function
Default: null

Callback to be executed when scrolling has started

onScrollUpdate New!
Type: function
Default: null

Callback to be executed when scrolling is running

onScrollEnd Previously 'callback'
Type: function
Default: null

Callback to be executed when scrolling has finished

fixedHeader
Type: string
Default: null

The header element
Example: '#fixed-header'

Here we go!