simple-scroll-to
v0.0.2
Published
A simple scrolling library.
Readme
Introduce
A simple scrolling tool.
Install
npm install simple-scroll-toHow to use
import { SimpleScrollTo } from 'simple-scroll-to';
const linear = (t) => t;
const easeInQuad = (t) => t * t;
const easeOutQuad = (t) => t * (2 - t);
const easeInOutQuad = (t) => (t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t);
const easeInCubic = (t) => t * t * t;
const easeOutCubic = (t) => --t * t * t + 1;
const easeInOutCubic = (t) => (t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1);
const dsInstance = new SimpleScrollTo({
isX: false,
start: window.scrollY,
end: window.scrollY + 1200,
duration: 700,
animation: easeInOutCubic,
callback() {
console.log('done');
},
});
const dsInstance_1 = new SimpleScrollTo({
isX: true,
start: window.scrollX,
end: window.scrollX + 200,
duration: 150,
});
setTimeout(() => {
dsInstance_1.cancel();
}, 300);
const dsInstance_2 = new SimpleScrollTo({
target: document.getElementById('target'),
isX: true,
start: 0,
end: 0 + 200,
duration: 150,
});