]> cat aescling's git repositories - mastodon.git/commitdiff
Use ScrollToOptions for smooth scrolling if supported (#11207)
authorThibG <thib@sitedethib.com>
Sat, 29 Jun 2019 16:32:06 +0000 (18:32 +0200)
committerEugen Rochko <eugen@zeonfederated.com>
Sat, 29 Jun 2019 16:32:06 +0000 (18:32 +0200)
app/javascript/mastodon/scroll.js

index 2af07e0fb1f04c727084e0b342d52a3d89b1a14a..84fe582699e9ddfd0547e4403dc30ad045a90262 100644 (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);