File tree Expand file tree Collapse file tree 2 files changed +37
-5
lines changed Expand file tree Collapse file tree 2 files changed +37
-5
lines changed Original file line number Diff line number Diff line change 7
7
</template >
8
8
9
9
<script >
10
+ const padding = 15 // tag's padding
11
+
10
12
export default {
11
13
name: ' scrollPane' ,
12
14
data () {
@@ -21,19 +23,37 @@ export default {
21
23
const $containerWidth = $container .offsetWidth
22
24
const $wrapper = this .$refs .scrollWrapper
23
25
const $wrapperWidth = $wrapper .offsetWidth
26
+
24
27
if (e .wheelDelta > 0 ) {
25
28
this .left = Math .min (0 , this .left + e .wheelDelta )
26
29
} else {
27
- if ($containerWidth - 100 < $wrapperWidth) {
28
- if (this .left < - ($wrapperWidth - $containerWidth + 100 )) {
30
+ if ($containerWidth - padding < $wrapperWidth) {
31
+ if (this .left < - ($wrapperWidth - $containerWidth + padding )) {
29
32
this .left = this .left
30
33
} else {
31
- this .left = Math .max (this .left + e .wheelDelta , $containerWidth - $wrapperWidth - 100 )
34
+ this .left = Math .max (this .left + e .wheelDelta , $containerWidth - $wrapperWidth - padding )
32
35
}
33
36
} else {
34
37
this .left = 0
35
38
}
36
39
}
40
+ },
41
+ moveToTarget ($target ) {
42
+ const $container = this .$refs .scrollContainer
43
+ const $containerWidth = $container .offsetWidth
44
+ const $targetLeft = $target .offsetLeft
45
+ const $targetWidth = $target .offsetWidth
46
+
47
+ if ($targetLeft < - this .left ) {
48
+ // tag in the left
49
+ this .left = - $targetLeft + padding
50
+ } else if ($targetLeft + padding > - this .left && $targetLeft + $targetWidth < - this .left + $containerWidth - padding) {
51
+ // tag in the current view
52
+ // eslint-disable-line
53
+ } else {
54
+ // tag in the right
55
+ this .left = - ($targetLeft - ($containerWidth - $targetWidth) + padding)
56
+ }
37
57
}
38
58
}
39
59
}
Original file line number Diff line number Diff line change 1
1
<template >
2
- <scroll-pane class =' tags-view-container' >
3
- <router-link class =" tags-view-item" :class =" isActive(tag)?'active':''" v-for =" tag in Array.from(visitedViews)" :to =" tag.path" :key =" tag.path" >
2
+ <scroll-pane class =' tags-view-container' ref = ' scrollPane ' >
3
+ <router-link ref = ' tag ' class =" tags-view-item" :class =" isActive(tag)?'active':''" v-for =" tag in Array.from(visitedViews)" :to =" tag.path" :key =" tag.path" >
4
4
{{$t('route.'+tag.title)}}
5
5
<span class =' el-icon-close' @click =' closeViewTags(tag,$event)' ></span >
6
6
</router-link >
@@ -49,12 +49,24 @@ export default {
49
49
},
50
50
isActive (route ) {
51
51
return route .path === this .$route .path || route .name === this .$route .name
52
+ },
53
+ moveToCurrentTag () {
54
+ const tags = this .$refs .tag
55
+ this .$nextTick (() => {
56
+ for (const tag of tags) {
57
+ if (tag .to === this .$route .path ) {
58
+ this .$refs .scrollPane .moveToTarget (tag .$el )
59
+ break
60
+ }
61
+ }
62
+ })
52
63
}
53
64
54
65
},
55
66
watch: {
56
67
$route () {
57
68
this .addViewTags ()
69
+ this .moveToCurrentTag ()
58
70
}
59
71
}
60
72
}
You can’t perform that action at this time.
0 commit comments