简体   繁体   English

jQuery,如何使元素一次通过一个动画

[英]Jquery, how to make an element go through one animation at a time

So I am trying to make an aquarium with jquery and javascript. 所以我试图用jquery和javascript制作一个水族馆。 Right now I am trying to make a fish become bigger for two seconds and then go back to its normal size. 现在,我试图使一条鱼变大两秒钟,然后恢复到正常大小。 I have encountered this problem where the fish becomes bigger for two seconds but if you during that time frame double click it again it will go back to its normal size and then immediately become twice the double size(of the initial double click). 我遇到了这样的问题,即鱼变大了两秒钟,但是如果您在这段时间内再次双击它,它将恢复到其正常大小,然后立即变成两倍大小(是初始双击的两倍)。 How do I fix this problem ? 我该如何解决这个问题? I want the fish to only become bigger once and then go back to normal size and if you double clicked during the time it was its double size nothing would happen. 我希望鱼只变大一次,然后恢复到正常大小,如果您在这段时间内双击它的两倍大小,将不会发生任何事情。

This is the code I used to make the fish enlarge: 这是我用来放大鱼的代码:

$("#fish1Id").dblclick(function(){
var heightNew = $(this).height() + 50;
var widthNew = $(this).width() + 50;

$(this).animate({height: heightNew, width: widthNew}, 500, shrink);


});

And shrink: 并缩小:

function shrink(){

$("#fish1Id").delay(2000).animate({height: redHeight, width: redWidth});

}

I figured it out on my own the fix I used: 我自己弄清楚了我使用的修复方法:

 $("#fish1Id").delay(1500).animate({height: redHeight, width: redWidth},function complete(){
      $("#fish1Id").stop(true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM