Socket
Socket
Sign inDemoInstall

@cher-ami/smooth-scroll

Package Overview
Dependencies
Maintainers
4
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cher-ami/smooth-scroll

Smooth scrool engine


Version published
Weekly downloads
0
decreased by-100%
Maintainers
4
Weekly downloads
 
Created
Source

🍃
Cher ami Smooth Scroll

A smooth scroll library


npm build l

Dependancies

Uses Signal

Summary

Installation

$ npm i @cher-ami/smooth-scroll

Simple usage

Init smooth scroll


const container = querySelector("#scroll-container")
const scrollManager = new SmoothScrollManager(container)
scrollManager.init()

Declare scroll sections


<div data-scroll-section></div>

To be counted in scroll flow, each element in container must be declared

API

Members
MemberTypeDescription
progressnumberPercentage of scroll progress
scrollPositionnumberCurrent scroll position in px (lerped value)
scrollDestinationnumberScroll destination in px (raw value)
scrollLengthnumberTotal scrollable length
scrollSpeednumberCurrent speed
Methods
MethodParamsDescription
init()noneInitialise scroll
scrollToTop(speed?)speed: number = 200Scroll to position 0
scrollToBottom(speed?)speed: number = 200Scroll to max position
scrollTo(target)target: number | HTMLDivElementScroll to destination in px or given HTML element
disable()noneDisable scroll
enable()noneEnable scroll
kill()noneCancel RAF and remove listeners
refresh()noneUpdate scroll sections and scroll length, should be called if the content of the scroll container has changed (ex: after page transitions)

React usage

Init

Wrap your app with <SmoothContainer />


export function App () {
  return (
      <div className={"root"}>
        <SmoothContainer>
          {/** ... */}
        </SmoothContainer>
      </div>
  )
}

Children will have access to scrollManager instance via ScrollContext


const scrollManager = useContext(ScrollContext)

API

Components :

Hooks :

SmoothContainer

Dispatch scrollContext to children and give them access to API


<SmoothContainer>
  {/** ... */}
</SmoothContainer>

Props :

none

useScrollPosition

Execute callback every time scroll position changes


useScrollPosition((scrollPosition: number) => {
  // Do something
}, []);

Parameters :

  • callback (scrollPositionValue:number) => void Callback function to execute each time the scroll position changes
  • dependancies any[] = [] Additional react dependancies

Returns :

nothing

useScrollSpeed

Execute callback every time scroll speed changes


useScrollSpeed((scrollSpeed: number) => {
  // Do something
}, []);

Parameters :

  • callback (scrollSpeedValue:number) => void Callback function to execute each time the scroll speed changes
  • dependancies any[] = [] Additional react dependancies

Returns :

nothing

Credits

Sam Phlix & Cher Ami

Keywords

FAQs

Package last updated on 12 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc