简体   繁体   English

带有CSS动画问题的jQuery Clickable Dropdown

[英]jQuery Clickable Dropdown with CSS Animation issue

Please check out this fiddle: https://jsfiddle.net/willbeeler/tfm8ohmw/ 请查看此小提琴: https : //jsfiddle.net/willbeeler/tfm8ohmw/

HTML: HTML:

<a href="#" class="roll-btn">Do it! Roll me down and up again!</a>
<ul class="roll-btns">
<li><a href="#" class="control animated noshow one">Milk</a></li>
<li><a href="#" class="control animated noshow two">Eggs and Cheese</a></li>
<li><a href="#" class="control animated noshow three">Bacon and Eggs</a></li>
<li><a href="#" class="control animated noshow four">Bread</a></li>
</ul> 

jQUERY 查询

$('.roll-btn').click(function() {

    var ctrls = '.control';

    if ($(ctrls).hasClass('noshow')) 
  {
    $(ctrls).each(function() {
       $(this).removeClass('noshow');
       $(this).addClass('fadeInDown');
    });
    } else {
    $(ctrls).each(function() {
       $(this).removeClass('fadeInDown');
       $(this).addClass('fadeOutDown');
    });
  }

});

This is a pretty simple thing, but I'm having trouble implementing it. 这是一件非常简单的事情,但是我在实现它时遇到了麻烦。 Basically, the class "noshow" is a toggle for the A elements. 基本上,类“ noshow”是A元素的切换。 If it does not exist, then add the CSS animation to the A element. 如果不存在,则将CSS动画添加到A元素。 If the CSS animation exists, add another css element to hide the A elements. 如果CSS动画存在,则添加另一个css元素以隐藏A元素。 I've tried delaying the "noshow" class, and other methods to no avail. 我尝试延迟“ noshow”类和其他方法无效。 This entire example works correctly with the first two clicks, but because it doesn't add the noshow class, it won't work after that. 整个示例在前两次单击时均能正常工作,但是由于未添加noshow类,因此此后将无法工作。 Basically, I need to add the noshow class on the second click AFTER the CSS animation gets done playing. 基本上,我需要在CSS动画播放完毕后第二次单击时添加noshow类。

$('.roll-btn').click(function() {

  var ctrls = '.control';

  if ($(ctrls).hasClass('noshow') || $(ctrls).hasClass('fadeOutDown')) {
    $(ctrls).each(function() {
      $(this).removeClass('noshow');
      $(this).addClass('fadeInDown');
      $(this).removeClass('fadeOutDown');
    });
  } else {
    $(ctrls).each(function() {
      $(this).removeClass('fadeInDown');
      $(this).addClass('fadeOutDown');
    });
  }
});

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

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