2015-11-05 63 views
0

我有一个关于.animate类的jQuery的问题。 是否不可能为同一类的多个对象设置动画效果? 不知何故,它不会工作。.animate不适用于多个对象

这里是它是如何在目前

<div class="demo"> 
    <div id="box1">hello</div> 
    <div id="box2">bye</div> 
</div> 

和JavaScript

function mySquare(name){ 

     this.animateMe = function(){ 
      $box = $("#" + name); 

      function there(){ 
       $box.animate(
       {left: 450 }, 2000, function(){ 
        //alert($box); 
        back(); 
       } 
       ); 
      } 

      function back(){ 
       $box.animate({left: 0 }, 2000, function(){ 
        there(); 
       } 
       ); 
      } 

      there($box); 
     }; 


    } 

    var square1 = new mySquare("box1"); 
    square1.animateMe(); 

    var square2 = new mySquare("box2"); 
    square2.animateMe(); 

http://jsfiddle.net/9ccuxyhw/

第一动画有后一种想法,只有第二个div不断动画和theres一个滞后 为什么第一个div停止动画?

比你的帮助

克里斯

回答

相关问题