fix(vuepress-plugin-back-to-top): fit the vuepress-plugin-smooth-scroll
This commit is contained in:
parent
5a3dcd5c25
commit
e025a610b3
@ -12,8 +12,6 @@ export default {
|
||||
data () {
|
||||
return {
|
||||
visible: false,
|
||||
interval: null,
|
||||
isMoving: false,
|
||||
/* eslint-disable no-undef */
|
||||
customStyle: CUSTOM_STYLE,
|
||||
visibilityHeight: VISIBILITY_HEIGHT
|
||||
@ -24,34 +22,13 @@ export default {
|
||||
},
|
||||
beforeDestroy () {
|
||||
window.removeEventListener('scroll', this.handleScroll)
|
||||
if (this.interval) {
|
||||
clearInterval(this.interval)
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
handleScroll () {
|
||||
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 <= 0) {
|
||||
window.scrollTo(0, 0)
|
||||
clearInterval(this.interval)
|
||||
this.isMoving = false
|
||||
} else {
|
||||
window.scrollTo(0, next)
|
||||
}
|
||||
i++
|
||||
}, 16.7)
|
||||
},
|
||||
easeInOutQuad (t, b, c, d) {
|
||||
if ((t /= d / 2) < 1) return c / 2 * t * t + b
|
||||
return -c / 2 * (--t * (t - 2) - 1) + b
|
||||
window.scrollTo(0, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user