qq_脱了缰的哈士奇_0
2020-07-25 10:50
我可以这样写吗
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)
}
这样移动看上去顺畅些
?
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)
}
这个可以加px吧,为什么下面加上面不加
手把手从0打造电商网页开发
16969 学习 · 58 问题
相似问题
回答 1