【问题标题】:Jquery toggle requires two clicks after first clickJquery 切换需要在第一次单击后单击两次
【发布时间】:2013-06-07 05:11:48
【问题描述】:

单击时我移动了两个 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( 函数 () {

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

});

【问题讨论】:

  • .toggle(fn1, fn2) 函数已弃用。

标签: jquery toggle


【解决方案1】:

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

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

SEE HERE

替代方案见HERE

【讨论】:

  • 所以我不能再使用它了……还是什么?
猜你喜欢
  • 1970-01-01
  • 2012-09-17
  • 1970-01-01
  • 2013-11-12
  • 1970-01-01
  • 1970-01-01
  • 2022-11-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多