Skip to content

Commit 85492f1

Browse files
committed
fix[scrollPane&&scrollBar]:fixed scroll bug in Firefox
1 parent b7ca786 commit 85492f1

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/components/ScrollBar/index.vue

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div class="scroll-container" ref="scrollContainer" @mousewheel="handleScroll">
2+
<div class="scroll-container" ref="scrollContainer" @wheel.prevent="handleScroll" >
33
<div class="scroll-wrapper" ref="scrollWrapper" :style="{top: top + 'px'}">
44
<slot></slot>
55
</div>
@@ -8,6 +8,7 @@
88

99
<script>
1010
const delta = 15
11+
1112
export default {
1213
name: 'scrollBar',
1314
data() {
@@ -17,19 +18,19 @@ export default {
1718
},
1819
methods: {
1920
handleScroll(e) {
20-
e.preventDefault()
21+
const eventDelta = e.wheelDelta || -e.deltaY * 3
2122
const $container = this.$refs.scrollContainer
2223
const $containerHeight = $container.offsetHeight
2324
const $wrapper = this.$refs.scrollWrapper
2425
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)
2728
} else {
2829
if ($containerHeight - delta < $wrapperHeight) {
2930
if (this.top < -($wrapperHeight - $containerHeight + delta)) {
3031
this.top = this.top
3132
} else {
32-
this.top = Math.max(this.top + e.wheelDelta, $containerHeight - $wrapperHeight - delta)
33+
this.top = Math.max(this.top + eventDelta, $containerHeight - $wrapperHeight - delta)
3334
}
3435
} else {
3536
this.top = 0

src/components/ScrollPane/index.vue

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div class="scroll-container" ref="scrollContainer" @mousewheel="handleScroll">
2+
<div class="scroll-container" ref="scrollContainer" @wheel.prevent="handleScroll">
33
<div class="scroll-wrapper" ref="scrollWrapper" :style="{left: left + 'px'}">
44
<slot></slot>
55
</div>
@@ -18,20 +18,20 @@ export default {
1818
},
1919
methods: {
2020
handleScroll(e) {
21-
e.preventDefault()
21+
const eventDelta = e.wheelDelta || -e.deltaY * 3
2222
const $container = this.$refs.scrollContainer
2323
const $containerWidth = $container.offsetWidth
2424
const $wrapper = this.$refs.scrollWrapper
2525
const $wrapperWidth = $wrapper.offsetWidth
2626
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)
2929
} else {
3030
if ($containerWidth - padding < $wrapperWidth) {
3131
if (this.left < -($wrapperWidth - $containerWidth + padding)) {
3232
this.left = this.left
3333
} else {
34-
this.left = Math.max(this.left + e.wheelDelta, $containerWidth - $wrapperWidth - padding)
34+
this.left = Math.max(this.left + eventDelta, $containerWidth - $wrapperWidth - padding)
3535
}
3636
} else {
3737
this.left = 0
@@ -64,6 +64,7 @@ export default {
6464
white-space: nowrap;
6565
position: relative;
6666
overflow: hidden;
67+
width: 100%;
6768
.scroll-wrapper {
6869
position: absolute;
6970
}

0 commit comments

Comments
 (0)