From 5b5b64d2514cf445aa81a6750ac4185f4e7dd8cd Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 12 Jul 2020 16:14:49 +0900 Subject: [PATCH] fix(client): Fix #6532 --- src/client/pages/index.home.vue | 3 ++- src/client/scripts/scroll.ts | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/client/pages/index.home.vue b/src/client/pages/index.home.vue index 2059b34ac3..927a3d6a08 100644 --- a/src/client/pages/index.home.vue +++ b/src/client/pages/index.home.vue @@ -30,6 +30,7 @@ import { faComments } from '@fortawesome/free-regular-svg-icons'; import Progress from '../scripts/loading'; import XTimeline from '../components/timeline.vue'; import XPostForm from '../components/post-form.vue'; +import { scroll } from '../scripts/scroll'; export default Vue.extend({ metaInfo() { @@ -120,7 +121,7 @@ export default Vue.extend({ }, top() { - window.scroll({ top: 0, behavior: 'instant' }); + scroll(this.$el, 0); }, async choose(ev) { diff --git a/src/client/scripts/scroll.ts b/src/client/scripts/scroll.ts index f32e50cdc7..a915f2e9ef 100644 --- a/src/client/scripts/scroll.ts +++ b/src/client/scripts/scroll.ts @@ -25,3 +25,12 @@ export function onScrollTop(el: Element, cb) { }; container.addEventListener('scroll', onScroll, { passive: true }); } + +export function scroll(el: Element, top: number) { + const container = getScrollContainer(el); + if (container == null) { + window.scroll({ top: top, behavior: 'instant' }); + } else { + container.scrollTop = top; + } +}