From 96cbbe3f3aa3167d5cb0caff03d234429077d877 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=91=A3=E9=9B=A8?= Date: Tue, 25 Dec 2018 18:10:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9currentTag=E4=B8=BA=E4=B8=AD?= =?UTF-8?q?=E9=97=B4tag=E6=97=B6=E6=9F=A5=E8=AF=A2=E5=89=8D=E5=90=8Etag?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ScrollPane/index.vue | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/src/components/ScrollPane/index.vue b/src/components/ScrollPane/index.vue index 89998e80..172afccc 100644 --- a/src/components/ScrollPane/index.vue +++ b/src/components/ScrollPane/index.vue @@ -28,8 +28,6 @@ export default { let firstTag = null let lastTag = null - let prevTag = null - let nextTag = null // find first tag and last tag if (tagList.length > 0) { @@ -37,26 +35,15 @@ export default { lastTag = tagList[tagList.length - 1] } - // find preTag and nextTag - for (let i = 0; i < tagList.length; i++) { - if (tagList[i] === currentTag) { - if (i === 0) { - nextTag = tagList[i].length > 1 && tagList[i + 1] - } else if (i === tagList.length - 1) { - prevTag = tagList[i].length > 1 && tagList[i - 1] - } else { - prevTag = tagList[i - 1] - nextTag = tagList[i + 1] - } - break - } - } - if (firstTag === currentTag) { $scrollWrapper.scrollLeft = 0 } else if (lastTag === currentTag) { $scrollWrapper.scrollLeft = $scrollWrapper.scrollWidth - $containerWidth } else { + // find preTag and nextTag + 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