Skip to content

Commit d8f967e

Browse files
ClearlyClaireGargron
authored andcommitted
Use ScrollToOptions for smooth scrolling if supported (mastodon#11207)
1 parent 5d8971e commit d8f967e

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

app/javascript/mastodon/scroll.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,7 @@ const scroll = (node, key, target) => {
2626
};
2727
};
2828

29-
export const scrollRight = (node, position) => scroll(node, 'scrollLeft', position);
30-
export const scrollTop = (node) => scroll(node, 'scrollTop', 0);
29+
const isScrollBehaviorSupported = 'scrollBehavior' in document.documentElement.style;
30+
31+
export const scrollRight = (node, position) => isScrollBehaviorSupported ? node.scrollTo({ left: position, behavior: 'smooth' }) : scroll(node, 'scrollLeft', position);
32+
export const scrollTop = (node) => isScrollBehaviorSupported ? node.scrollTo({ top: 0, behavior: 'smooth' }) : scroll(node, 'scrollTop', 0);

0 commit comments

Comments
 (0)