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