scroll-to-by-speed
v2.0.0
Published
Animated scrolling should be a function of speed, not time.
Downloads
3
Readme
scroll-to-by-speed
Animated scrolling should be a function of speed, not time.
There are lots of ways to scroll that accept a duration argument. This library doesn't handle scrolling for you, but it will calculate the duration based on speed given an element, a direction, and a context.
You might be thinking that you don't need a library for this. That's good. This library exists to promote the concept.
Usage
function scroll(element, duration) {
// your favorite scrolling technique goes here
}
var speed = 1000; // pixels per second
var element = document.querySelector('div');
var duration = scrollToBySpeed({ speed, element });
scroll(element, duration);