fix[backToTop]: continuous click bug #1007
This commit is contained in:
parent
00d292f67e
commit
2e1f36fe00
|
@ -45,7 +45,8 @@ export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
visible: false,
|
visible: false,
|
||||||
interval: null
|
interval: null,
|
||||||
|
isMoving: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
|
@ -62,13 +63,16 @@ export default {
|
||||||
this.visible = window.pageYOffset > this.visibilityHeight
|
this.visible = window.pageYOffset > this.visibilityHeight
|
||||||
},
|
},
|
||||||
backToTop() {
|
backToTop() {
|
||||||
|
if (this.isMoving) return
|
||||||
const start = window.pageYOffset
|
const start = window.pageYOffset
|
||||||
let i = 0
|
let i = 0
|
||||||
|
this.isMoving = true
|
||||||
this.interval = setInterval(() => {
|
this.interval = setInterval(() => {
|
||||||
const next = Math.floor(this.easeInOutQuad(10 * i, start, -start, 500))
|
const next = Math.floor(this.easeInOutQuad(10 * i, start, -start, 500))
|
||||||
if (next <= this.backPosition) {
|
if (next <= this.backPosition) {
|
||||||
window.scrollTo(0, this.backPosition)
|
window.scrollTo(0, this.backPosition)
|
||||||
clearInterval(this.interval)
|
clearInterval(this.interval)
|
||||||
|
this.isMoving = false
|
||||||
} else {
|
} else {
|
||||||
window.scrollTo(0, next)
|
window.scrollTo(0, next)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue