Jquery toggle requires two clicks after first click

最后都变了- 提交于 2020-01-06 06:59:23

问题


I move two divs (open) when clicking, when the user clicks, I want the rest to reset. (It looks pretty clear in my fiddle)

The first time I run the script and click the objects, it works flawless, but if I continue clicking, it requires two clicks to function. I've tried functions involving .click() and e.preventdefault, but none of it worked. I've already spend to much time on this, so I hope someone can help me out on this.

Many thanks in advance!

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'});

});


回答1:


.toggle() is deprecated in latest version

This method signature was deprecated in jQuery 1.8 and removed in jQuery 1.9. jQuery also provides an animation method named .toggle() that toggles the visibility of elements. Whether the animation or the event method is fired depends on the set of arguments passed.

SEE HERE

For alternative see HERE



来源:https://stackoverflow.com/questions/17042647/jquery-toggle-requires-two-clicks-after-first-click

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