diff options
author | ThibG <thib@sitedethib.com> | 2019-06-29 18:32:06 +0200 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2019-06-29 18:32:06 +0200 |
commit | 84ff3938426da348e31651dfad376d83a9784343 (patch) | |
tree | 422a8be804728b5814de5bb00ba0f6cca70a2e19 | |
parent | 4f5b221be21e62257c16e47e998cdf757991f871 (diff) |
Use ScrollToOptions for smooth scrolling if supported (#11207)
-rw-r--r-- | app/javascript/mastodon/scroll.js | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/app/javascript/mastodon/scroll.js b/app/javascript/mastodon/scroll.js index 2af07e0fb..84fe58269 100644 --- a/app/javascript/mastodon/scroll.js +++ b/app/javascript/mastodon/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); |