about summary refs log tree commit diff
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2019-06-29 18:32:06 +0200
committerThibaut Girka <thib@sitedethib.com>2019-06-30 11:01:01 +0200
commit46829e009ee26603e3f3462cba4c054939aac3dd (patch)
tree9f661dbfd6c586049f348c59e146195f9d3aa0e5
parentc5495a448cee117a1ed831991375f0c2f6a43594 (diff)
[Glitch] Use ScrollToOptions for smooth scrolling if supported
Port 84ff3938426da348e31651dfad376d83a9784343 to glitch-soc

Signed-off-by: Thibaut Girka <thib@sitedethib.com>
-rw-r--r--app/javascript/flavours/glitch/util/scroll.js6
1 files changed, 4 insertions, 2 deletions
diff --git a/app/javascript/flavours/glitch/util/scroll.js b/app/javascript/flavours/glitch/util/scroll.js
index 2af07e0fb..84fe58269 100644
--- a/app/javascript/flavours/glitch/util/scroll.js
+++ b/app/javascript/flavours/glitch/util/scroll.js
@@ -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);