首次单击后,Jquery切换需要两次单击

我点击时移动两个div(打开),当用户点击时,我希望其余的重置。 (我的小提琴看起来很清楚)

我第一次运行脚本并单击对象时,它完美无瑕,但如果我继续单击,则需要两次单击才能运行。 我尝试过涉及.click()和e.preventdefault的函数,但没有一个工作。 我已经花了很多时间在这上面,所以我希望有人可以帮我解决这个问题。

提前谢谢了!

http://jsfiddle.net/baZDy/

$("#schoenen").toggle( 

function(){

 //schoenen $("#rood_een").animate({'left':'480px'}); $("#rood_twee").animate({'top':'120px'}); //casual $("#oranje_een").animate({'left':'240px'}); $("#oranje_twee").animate({'top':'120px'}); //schoenen //$("#rood_een").animate({'left':'360px'}); //$("#rood_twee").animate({'top':'0px'}); //ceremonie $("#blauw_een").animate({'left':'120px'}); $("#blauw_twee").animate({'top':'240px'}); //communie $("#groen_een").animate({'left':'240px'}); $("#groen_twee").animate({'top':'360px'}); 

},function(){

 $("#rood_een").animate({'left':'360px'}); $("#rood_twee").animate({'top':'0px'}); 

});

$(“#casual”)。toggle(function(){

 //casual $("#oranje_een").animate({'left':'120px'}); $("#oranje_twee").animate({'top':'0px'}); //casual 

// $(“#oranje_een”)。animate({‘left’:’240px’}); //$(“#oranje_twee”).animate({‘top’:’120px’});

 //schoenen $("#rood_een").animate({'left':'360px'}); $("#rood_twee").animate({'top':'0px'}); //ceremonie $("#blauw_een").animate({'left':'120px'}); $("#blauw_twee").animate({'top':'240px'}); //communie $("#groen_een").animate({'left':'240px'}); $("#groen_twee").animate({'top':'360px'}); 

},function(){

 $("#oranje_een").animate({'left':'240px'}); $("#oranje_twee").animate({'top':'120px'}); 

});

.toggle()在最新版本中已弃用

此方法签名在jQuery 1.8中已弃用,并在jQuery 1.9中删除。 jQuery还提供了一个名为.toggle()的动画方法,可以切换元素的可见性。 是否触发动画或事件方法取决于传递的参数集。

看这里

如需替代,请参阅此处