Start an animation when the other one is finished/completed in jquery

六眼飞鱼酱① 提交于 2020-01-07 09:02:09

问题


This is not working for me:

$(".button").click(function(){ 
    $("#start").animate({
        "opacity": ".3"
    }, "slow", function(){
        $("#start").animate({"height": "0"}, "fast");
    });
});

I want a div to animate and when it's done, animate again.

Doesn't matter what I search on Google... on all the blogs and forums it says that this should be the only way to do it.


回答1:


Looks like we'll need to see your html. Works fine for me:

http://jsfiddle.net/LTHtb/

<div class="button">start</div>

<div id="start"></div>

<script>
$(".button").click(function(){ 
$("#start").animate({
"opacity": ".3"
}, "slow", function(){
$("#start").animate({"height": "0"}, "fast");
    });
});
</script>

CSS:

 #start{
 height:200px;
  width:200px;
  margin-top:20px; 
  background-color:#e1e1e1;
}

.button{
   padding:10px;
   background-color:#369; 
   cursor: pointer;
   width:200px;
}



回答2:


For an endless animation loop, you could use this:

function animate() { 
  $("#start").animate({opacity: .3}, "slow", 
    function () {
      $("#start").animate({height: 0}, "fast", animate);
    }
  );
}

$(".button").click(animate);



回答3:


Probably you are looking for slideUp() function. Anyway your code works fine:

Code: http://jsfiddle.net/nbnV6/1/



来源:https://stackoverflow.com/questions/8259361/start-an-animation-when-the-other-one-is-finished-completed-in-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!