Browse Source

[Glitch] Use ScrollToOptions for smooth scrolling if supported

Port 84ff393842 to glitch-soc

Signed-off-by: Thibaut Girka <thib@sitedethib.com>
closed-social-glitch-2
ThibG 5 years ago
committed by Thibaut Girka
parent
commit
46829e009e
1 changed files with 4 additions and 2 deletions
  1. +4
    -2
      app/javascript/flavours/glitch/util/scroll.js

+ 4
- 2
app/javascript/flavours/glitch/util/scroll.js View File

@ -26,5 +26,7 @@ const scroll = (node, key, target) => {
};
};
export const scrollRight = (node, position) => scroll(node, 'scrollLeft', position);
export const scrollTop = (node) => scroll(node, 'scrollTop', 0);
const isScrollBehaviorSupported = 'scrollBehavior' in document.documentElement.style;
export const scrollRight = (node, position) => isScrollBehaviorSupported ? node.scrollTo({ left: position, behavior: 'smooth' }) : scroll(node, 'scrollLeft', position);
export const scrollTop = (node) => isScrollBehaviorSupported ? node.scrollTo({ top: 0, behavior: 'smooth' }) : scroll(node, 'scrollTop', 0);

Loading…
Cancel
Save