gearheads
/
mastodon
Archived
2
0
Fork 0

Use ScrollToOptions for smooth scrolling if supported (#11207)

gh/stable
ThibG 2019-06-29 18:32:06 +02:00 committed by Eugen Rochko
parent 4f5b221be2
commit 84ff393842
1 changed files with 4 additions and 2 deletions

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