【问题标题】:Help with this animation loop帮助这个动画循环
【发布时间】:2011-10-21 13:28:32
【问题描述】:
t.grow = function(parent,evt) { 
evt.target.Y = 0
var r = parent.radius, that = this
this.loop = function() {
    parent.root.suspendRedraw(10000)
    evt.target.Y = evt.target.Y - 6
    evt.target.setAttribute('transform', 
              'translate(' + 0 + ',' + evt.target.Y + ')')
    r = r + 0.1
    evt.target.setAttribute('r',r)
    parent.root.unsuspendRedrawAll()
     if(evt.target.Y < parent.timeout) {
        clearInterval(that.timer)
     }
}
that.timer = window.setInterval(this.loop,30) 
}
this.el.addEventListener("mouseover",
function(event){ 
    t.grow(parent,event)
},
true) 

我真的需要一些关于上述动画的帮助。

目前动画是在对象的鼠标悬停时触发的,但我真正想要实现的不是动画被触发的事件,而是我希望它在随机时间触发的事件

【问题讨论】:

    标签: javascript animation canvas svg


    【解决方案1】:
    function start(){
      grow()//You will need to pass in whatever element you want this to act on.
      setTimeout(function(){start()},(Math.floor(Math.random()*10)+5)*1000);
    }
    

    基本上,第二行创建一个介于 0 和 10 之间的随机数,然后添加 5,这样您就不会有两个动画连续运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-06-07
      • 1970-01-01
      • 2011-01-27
      • 1970-01-01
      • 2021-12-26
      • 2010-09-26
      • 2010-09-23
      相关资源
      最近更新 更多