logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

scroll.js (773B)


  1. const easingOutQuint = (x, t, b, c, d) => c * ((t = t / d - 1) * t * t * t * t + 1) + b;
  2. const scroll = (node, key, target) => {
  3. const startTime = Date.now();
  4. const offset = node[key];
  5. const gap = target - offset;
  6. const duration = 1000;
  7. let interrupt = false;
  8. const step = () => {
  9. const elapsed = Date.now() - startTime;
  10. const percentage = elapsed / duration;
  11. if (percentage > 1 || interrupt) {
  12. return;
  13. }
  14. node[key] = easingOutQuint(0, elapsed, offset, gap, duration);
  15. requestAnimationFrame(step);
  16. };
  17. step();
  18. return () => {
  19. interrupt = true;
  20. };
  21. };
  22. export const scrollRight = (node, position) => scroll(node, 'scrollLeft', position);
  23. export const scrollTop = (node) => scroll(node, 'scrollTop', 0);