关于animate函数
我可以这样写吗
animate(offset) {
const time = 1000
const rate = 10
let speed = offset/(time/rate)
let goal = parseFloat(this.picBox.style.left) - offset
let animate = setInterval(() => {
if ( this.picBox.style.left == goal || Math.abs(Math.abs(parseFloat(this.picBox.style.left)) - Math.abs(goal)) < Math.abs(speed) ) {
this.picBox.style.left = goal + "px"
clearInterval(animate)
} else {
this.picBox.style.left = parseFloat(this.picBox.style.left) - speed + "px"
}
}, rate)
}
这样移动看上去顺畅些