Skip to content

Commit

Permalink
perf[ScrollPane]: refine moveToTarget code (PanJiaChen#1460)
Browse files Browse the repository at this point in the history
  • Loading branch information
rainydayDY authored and PanJiaChen committed Dec 26, 2018
1 parent afdb893 commit 07c3211
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions src/components/ScrollPane/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,22 @@ export default {
let firstTag = null
let lastTag = null
let prevTag = null
let nextTag = null
// find first tag and last tag
if (tagList.length > 0) {
firstTag = tagList[0]
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
Expand Down

0 comments on commit 07c3211

Please sign in to comment.