2.0.0 • Published 5 years ago

scroll-to-by-speed v2.0.0

Weekly downloads
5
License
ISC
Repository
github
Last release
5 years ago

scroll-to-by-speed

repo npm

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);