File tree Expand file tree Collapse file tree 1 file changed +4
-17
lines changed
src/components/ScrollPane Expand file tree Collapse file tree 1 file changed +4
-17
lines changed Original file line number Diff line number Diff line change @@ -28,35 +28,22 @@ export default {
28
28
29
29
let firstTag = null
30
30
let lastTag = null
31
- let prevTag = null
32
- let nextTag = null
33
31
34
32
// find first tag and last tag
35
33
if (tagList .length > 0 ) {
36
34
firstTag = tagList[0 ]
37
35
lastTag = tagList[tagList .length - 1 ]
38
36
}
39
37
40
- // find preTag and nextTag
41
- for (let i = 0 ; i < tagList .length ; i++ ) {
42
- if (tagList[i] === currentTag) {
43
- if (i === 0 ) {
44
- nextTag = tagList[i].length > 1 && tagList[i + 1 ]
45
- } else if (i === tagList .length - 1 ) {
46
- prevTag = tagList[i].length > 1 && tagList[i - 1 ]
47
- } else {
48
- prevTag = tagList[i - 1 ]
49
- nextTag = tagList[i + 1 ]
50
- }
51
- break
52
- }
53
- }
54
-
55
38
if (firstTag === currentTag) {
56
39
$scrollWrapper .scrollLeft = 0
57
40
} else if (lastTag === currentTag) {
58
41
$scrollWrapper .scrollLeft = $scrollWrapper .scrollWidth - $containerWidth
59
42
} else {
43
+ // find preTag and nextTag
44
+ const currentIndex = tagList .findIndex (item => item === currentTag)
45
+ const prevTag = tagList[currentIndex - 1 ]
46
+ const nextTag = tagList[currentIndex + 1 ]
60
47
// the tag's offsetLeft after of nextTag
61
48
const afterNextTagOffsetLeft = nextTag .$el .offsetLeft + nextTag .$el .offsetWidth + tagAndTagSpacing
62
49
You can’t perform that action at this time.
0 commit comments