File tree Expand file tree Collapse file tree 2 files changed +12
-10
lines changed Expand file tree Collapse file tree 2 files changed +12
-10
lines changed Original file line number Diff line number Diff line change 1
1
<template >
2
- <div class =" scroll-container" ref =" scrollContainer" @mousewheel =" handleScroll" >
2
+ <div class =" scroll-container" ref =" scrollContainer" @wheel.prevent =" handleScroll" >
3
3
<div class =" scroll-wrapper" ref =" scrollWrapper" :style =" {top: top + 'px'}" >
4
4
<slot ></slot >
5
5
</div >
8
8
9
9
<script >
10
10
const delta = 15
11
+
11
12
export default {
12
13
name: ' scrollBar' ,
13
14
data () {
@@ -17,19 +18,19 @@ export default {
17
18
},
18
19
methods: {
19
20
handleScroll (e ) {
20
- e . preventDefault ()
21
+ const eventDelta = e . wheelDelta || - e . deltaY * 3
21
22
const $container = this .$refs .scrollContainer
22
23
const $containerHeight = $container .offsetHeight
23
24
const $wrapper = this .$refs .scrollWrapper
24
25
const $wrapperHeight = $wrapper .offsetHeight
25
- if (e . wheelDelta > 0 ) {
26
- this .top = Math .min (0 , this .top + e . wheelDelta )
26
+ if (eventDelta > 0 ) {
27
+ this .top = Math .min (0 , this .top + eventDelta )
27
28
} else {
28
29
if ($containerHeight - delta < $wrapperHeight) {
29
30
if (this .top < - ($wrapperHeight - $containerHeight + delta)) {
30
31
this .top = this .top
31
32
} else {
32
- this .top = Math .max (this .top + e . wheelDelta , $containerHeight - $wrapperHeight - delta)
33
+ this .top = Math .max (this .top + eventDelta , $containerHeight - $wrapperHeight - delta)
33
34
}
34
35
} else {
35
36
this .top = 0
Original file line number Diff line number Diff line change 1
1
<template >
2
- <div class =" scroll-container" ref =" scrollContainer" @mousewheel =" handleScroll" >
2
+ <div class =" scroll-container" ref =" scrollContainer" @wheel.prevent =" handleScroll" >
3
3
<div class =" scroll-wrapper" ref =" scrollWrapper" :style =" {left: left + 'px'}" >
4
4
<slot ></slot >
5
5
</div >
@@ -18,20 +18,20 @@ export default {
18
18
},
19
19
methods: {
20
20
handleScroll (e ) {
21
- e . preventDefault ()
21
+ const eventDelta = e . wheelDelta || - e . deltaY * 3
22
22
const $container = this .$refs .scrollContainer
23
23
const $containerWidth = $container .offsetWidth
24
24
const $wrapper = this .$refs .scrollWrapper
25
25
const $wrapperWidth = $wrapper .offsetWidth
26
26
27
- if (e . wheelDelta > 0 ) {
28
- this .left = Math .min (0 , this .left + e . wheelDelta )
27
+ if (eventDelta > 0 ) {
28
+ this .left = Math .min (0 , this .left + eventDelta )
29
29
} else {
30
30
if ($containerWidth - padding < $wrapperWidth) {
31
31
if (this .left < - ($wrapperWidth - $containerWidth + padding)) {
32
32
this .left = this .left
33
33
} else {
34
- this .left = Math .max (this .left + e . wheelDelta , $containerWidth - $wrapperWidth - padding)
34
+ this .left = Math .max (this .left + eventDelta , $containerWidth - $wrapperWidth - padding)
35
35
}
36
36
} else {
37
37
this .left = 0
@@ -64,6 +64,7 @@ export default {
64
64
white-space : nowrap ;
65
65
position : relative ;
66
66
overflow : hidden ;
67
+ width : 100% ;
67
68
.scroll-wrapper {
68
69
position : absolute ;
69
70
}
You can’t perform that action at this time.
0 commit comments