0.0.1 • Published 3 years ago

@dims/smooth-scroll-to v0.0.1

Weekly downloads
142
License
ISC
Repository
github
Last release
3 years ago

Description

Pure js smooth scroll functionality using a class syntax.

API

OPTIONTYPEDEFAULT VALUEDESCRIPTION
axisString"y"Can scroll along the "x" or the "y" axis.
callbackFunctionNOOPCalled when scrolling has finished.
durationNumber400Duration of the scroll in miliseconds.
easingString"easeOut"Easing type - linear ,easeOut, easeIn, easeInOut.
targetObjectwindowCan be window or any DOM element with overflow: auto.
toNumber0X or Y coordinate to scroll to (relative to the target element, not to the current scroll position).

Code Examples

window.addEventListener("load", () => {
  document.querySelector("#button").addEventListener("click", () => {
    const smoothScroll = new SmoothScrollTo({
      to: 1200,
      callback: () => {
        console.log("end");
      }
    });

    smoothScroll.init();
  });
});