Transcroll
Animate scroll in a flexible, user-friendly, simple and modern way.
Install with npm i transcroll
.
Usage:
import transcroll, { easings } from './index';
transcroll(document.querySelector('#whatever'));
transcroll('#whatever');
transcroll(200);
transcroll(whatever, {
el: window,
offset: 0,
axis: 'y',
duration: 200,
easing: easings.easeInQuad,
jump: 2,
interrupt: true
});
transcroll(whatever).then(({
// animation started after "jump" is triggered
jumped,
// animation was interrupted by user
interrupted
}) => doSomething());
Jump factor
jump
argument is used to calculate a threshold value which is used to prevent animating too big distances in a
short period of time.
threshold = duration * jumpFactor
You can feel same behavior in the Telegram application when trying to scroll to the last message in a chat after
scrolling back to some old messages about 4-5 screens.