fix[scrollPane&&scrollBar]:fixed scroll bug in Firefox
This commit is contained in:
parent
b7ca786751
commit
85492f148f
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="scroll-container" ref="scrollContainer" @mousewheel="handleScroll">
|
<div class="scroll-container" ref="scrollContainer" @wheel.prevent="handleScroll" >
|
||||||
<div class="scroll-wrapper" ref="scrollWrapper" :style="{top: top + 'px'}">
|
<div class="scroll-wrapper" ref="scrollWrapper" :style="{top: top + 'px'}">
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
</div>
|
</div>
|
||||||
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const delta = 15
|
const delta = 15
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'scrollBar',
|
name: 'scrollBar',
|
||||||
data() {
|
data() {
|
||||||
|
@ -17,19 +18,19 @@ export default {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
handleScroll(e) {
|
handleScroll(e) {
|
||||||
e.preventDefault()
|
const eventDelta = e.wheelDelta || -e.deltaY * 3
|
||||||
const $container = this.$refs.scrollContainer
|
const $container = this.$refs.scrollContainer
|
||||||
const $containerHeight = $container.offsetHeight
|
const $containerHeight = $container.offsetHeight
|
||||||
const $wrapper = this.$refs.scrollWrapper
|
const $wrapper = this.$refs.scrollWrapper
|
||||||
const $wrapperHeight = $wrapper.offsetHeight
|
const $wrapperHeight = $wrapper.offsetHeight
|
||||||
if (e.wheelDelta > 0) {
|
if (eventDelta > 0) {
|
||||||
this.top = Math.min(0, this.top + e.wheelDelta)
|
this.top = Math.min(0, this.top + eventDelta)
|
||||||
} else {
|
} else {
|
||||||
if ($containerHeight - delta < $wrapperHeight) {
|
if ($containerHeight - delta < $wrapperHeight) {
|
||||||
if (this.top < -($wrapperHeight - $containerHeight + delta)) {
|
if (this.top < -($wrapperHeight - $containerHeight + delta)) {
|
||||||
this.top = this.top
|
this.top = this.top
|
||||||
} else {
|
} else {
|
||||||
this.top = Math.max(this.top + e.wheelDelta, $containerHeight - $wrapperHeight - delta)
|
this.top = Math.max(this.top + eventDelta, $containerHeight - $wrapperHeight - delta)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.top = 0
|
this.top = 0
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="scroll-container" ref="scrollContainer" @mousewheel="handleScroll">
|
<div class="scroll-container" ref="scrollContainer" @wheel.prevent="handleScroll">
|
||||||
<div class="scroll-wrapper" ref="scrollWrapper" :style="{left: left + 'px'}">
|
<div class="scroll-wrapper" ref="scrollWrapper" :style="{left: left + 'px'}">
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
</div>
|
</div>
|
||||||
|
@ -18,20 +18,20 @@ export default {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
handleScroll(e) {
|
handleScroll(e) {
|
||||||
e.preventDefault()
|
const eventDelta = e.wheelDelta || -e.deltaY * 3
|
||||||
const $container = this.$refs.scrollContainer
|
const $container = this.$refs.scrollContainer
|
||||||
const $containerWidth = $container.offsetWidth
|
const $containerWidth = $container.offsetWidth
|
||||||
const $wrapper = this.$refs.scrollWrapper
|
const $wrapper = this.$refs.scrollWrapper
|
||||||
const $wrapperWidth = $wrapper.offsetWidth
|
const $wrapperWidth = $wrapper.offsetWidth
|
||||||
|
|
||||||
if (e.wheelDelta > 0) {
|
if (eventDelta > 0) {
|
||||||
this.left = Math.min(0, this.left + e.wheelDelta)
|
this.left = Math.min(0, this.left + eventDelta)
|
||||||
} else {
|
} else {
|
||||||
if ($containerWidth - padding < $wrapperWidth) {
|
if ($containerWidth - padding < $wrapperWidth) {
|
||||||
if (this.left < -($wrapperWidth - $containerWidth + padding)) {
|
if (this.left < -($wrapperWidth - $containerWidth + padding)) {
|
||||||
this.left = this.left
|
this.left = this.left
|
||||||
} else {
|
} else {
|
||||||
this.left = Math.max(this.left + e.wheelDelta, $containerWidth - $wrapperWidth - padding)
|
this.left = Math.max(this.left + eventDelta, $containerWidth - $wrapperWidth - padding)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.left = 0
|
this.left = 0
|
||||||
|
@ -64,6 +64,7 @@ export default {
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
position: relative;
|
position: relative;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
width: 100%;
|
||||||
.scroll-wrapper {
|
.scroll-wrapper {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue