From ef8598b74dd0cbb5658970f068a88392adefdf15 Mon Sep 17 00:00:00 2001 From: Pan Date: Tue, 5 Mar 2019 13:00:14 +0800 Subject: [PATCH] format --- src/views/layout/components/TagsView/ScrollPane.vue | 5 +++++ src/views/layout/components/TagsView/index.vue | 1 + 2 files changed, 6 insertions(+) diff --git a/src/views/layout/components/TagsView/ScrollPane.vue b/src/views/layout/components/TagsView/ScrollPane.vue index eebafd5a..b9d490dc 100644 --- a/src/views/layout/components/TagsView/ScrollPane.vue +++ b/src/views/layout/components/TagsView/ScrollPane.vue @@ -30,13 +30,16 @@ export default { const $containerWidth = $container.offsetWidth const $scrollWrapper = this.scrollWrapper const tagList = this.$parent.$refs.tag + let firstTag = null let lastTag = null + // find first tag and last tag if (tagList.length > 0) { firstTag = tagList[0] lastTag = tagList[tagList.length - 1] } + if (firstTag === currentTag) { $scrollWrapper.scrollLeft = 0 } else if (lastTag === currentTag) { @@ -46,8 +49,10 @@ export default { const currentIndex = tagList.findIndex(item => item === currentTag) const prevTag = tagList[currentIndex - 1] const nextTag = tagList[currentIndex + 1] + // the tag's offsetLeft after of nextTag const afterNextTagOffsetLeft = nextTag.$el.offsetLeft + nextTag.$el.offsetWidth + tagAndTagSpacing + // the tag's offsetLeft before of prevTag const beforePrevTagOffsetLeft = prevTag.$el.offsetLeft - tagAndTagSpacing if (afterNextTagOffsetLeft > $scrollWrapper.scrollLeft + $containerWidth) { diff --git a/src/views/layout/components/TagsView/index.vue b/src/views/layout/components/TagsView/index.vue index fc49d9cb..4cd1b780 100644 --- a/src/views/layout/components/TagsView/index.vue +++ b/src/views/layout/components/TagsView/index.vue @@ -29,6 +29,7 @@ import ScrollPane from './ScrollPane' import { generateTitle } from '@/utils/i18n' import path from 'path' + export default { components: { ScrollPane }, data() {