为了账号安全,请及时绑定邮箱和手机立即绑定

关于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)


    }

这样移动看上去顺畅些

正在回答

1 回答

?

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 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
手把手从0打造电商网页开发
  • 参与学习       16961    人
  • 解答问题       58    个

手把手教你实现电商网站开发之高仿京东商城网页

进入课程

关于animate函数

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信