0

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

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

提前谢谢了!

http://jsfiddle.net/baZDy/

$("#schoenen").toggle(

功能 () {

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

}, 功能 () {

$("#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'});

}, 功能 () {

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

});

4

1 回答 1

0

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

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

看这里

有关替代方案,请参见此处

于 2013-06-11T11:10:12.090 回答