vayaraw
v0.0.75
Published
A lightweight smooth scrolling library for web projects.
Maintainers
Readme
Vayara
Vayara is a library for smooth scrolling in web projects. It enhances user experience by adding inertia and smooth scrolling with customizable parameters.
Installation
Install the library using npm or yarn:
npm install vayaraor
yarn add vayaraUsage
Import and Initialization
import createSmoothScroll from 'vayara';
const smoothScroll = createSmoothScroll({
wrapper: window, // Scroll container
content: document.documentElement, // Content inside the container
smooth: 0.1, // Smoothness level (from 0 to 1)
direction: 'vertical', // Scrolling direction ('vertical' | 'horizontal')
smoothWheel: true, // Enable smooth scrolling with the mouse wheel
maxScrollSpeed: 100, // Maximum scrolling speed
normalizeSmooth: true, // Normalize smoothness
subPixelControl: 5, // Subpixel movement control
});Methods
start()
Starts the smooth scrolling animation.
smoothScroll.start();stop()
Stops smooth scrolling.
smoothScroll.stop();destroy()
Completely removes event handlers and disables smooth scrolling.
smoothScroll.destroy();on('scroll', callback)
Allows subscribing to the scroll event.
smoothScroll.on('scroll', (event) => {
console.log('Current position:', event.scroll);
console.log('Scroll velocity:', event.velocity);
console.log('Direction:', event.direction);
});off('scroll', callback)
Unsubscribes from the scroll event.
smoothScroll.off('scroll', callback);Options
| Option | Type | Description |
| ----------------- | ------------------------------ | ------------------------------------------------------------------------------ |
| wrapper | HTMLElement or Window | The container where scrolling occurs. |
| content | HTMLElement | The element containing the content inside the container. |
| smooth | number (0-1) | Smoothness coefficient (from 0 for no smoothness to 1 for maximum smoothness). |
| direction | 'vertical' or 'horizontal' | Scroll direction. |
| smoothWheel | boolean | Enables/disables smooth scrolling with the mouse wheel. |
| maxScrollSpeed | number | Maximum scrolling speed. |
| normalizeSmooth | boolean | Normalizes animation smoothness for consistent performance. |
| subPixelControl | number | Subpixel movement control. |
License
Vayara is distributed under the MIT license.
