You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
773 B
31 lines
773 B
![]()
7 years ago
|
const easingOutQuint = (x, t, b, c, d) => c * ((t = t / d - 1) * t * t * t * t + 1) + b;
|
||
|
|
||
![]()
7 years ago
|
const scroll = (node, key, target) => {
|
||
![]()
7 years ago
|
const startTime = Date.now();
|
||
![]()
7 years ago
|
const offset = node[key];
|
||
|
const gap = target - offset;
|
||
![]()
7 years ago
|
const duration = 1000;
|
||
|
let interrupt = false;
|
||
|
|
||
|
const step = () => {
|
||
|
const elapsed = Date.now() - startTime;
|
||
|
const percentage = elapsed / duration;
|
||
|
|
||
|
if (percentage > 1 || interrupt) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
![]()
7 years ago
|
node[key] = easingOutQuint(0, elapsed, offset, gap, duration);
|
||
![]()
7 years ago
|
requestAnimationFrame(step);
|
||
|
};
|
||
|
|
||
|
step();
|
||
|
|
||
|
return () => {
|
||
|
interrupt = true;
|
||
|
};
|
||
|
};
|
||
|
|
||
![]()
7 years ago
|
export const scrollRight = (node, position) => scroll(node, 'scrollLeft', position);
|
||
![]()
7 years ago
|
export const scrollTop = (node) => scroll(node, 'scrollTop', 0);
|