如何通过单击制作动画进出动画的CSS动画

时间:2014-03-28 14:40:55

标签: jquery css css3 toggle css-animations

我对如何使用CSS动画动画进出我点击元素的动画感到困惑。

我可以在工作中获得动画,但由于某种原因,动画片无效。我正在交换类名来切换不同的动画,名称切换正常,但动画只是不好。

如果有人能指出我的错误,我会非常感激。

抱歉,我知道这是很多代码。

这是我的 SCSS

.animate-in .twitter, .animate-in .google-plus, .animate-in .facebook,
.animate-out .twitter, .animate-out .google-plus, .animate-out .facebook{
    @include animation-name(dropIn, fadeIn, dropShadow);
    @include animation-duration(500ms);
    @include animation-delay(0ms);
    @include animation-direction(alternate);
    @include animation-fill-mode(forwards);  

}
.animate-out .twitter, .animate-out .google-plus, .animate-out .facebook{
    @include animation-name(fadeOut);
    @include animation-duration(500ms);
    @include animation-delay(0ms);
    @include animation-play-state(play);
    @include animation-fill-mode(forwards);  
}
.animate-in .google-plus,
.animate-out .google-plus{
    @include animation-delay(150ms);
    @include animation-timing-function(cubic-bezier(0.77, 0, 0.175, 1));
}
.animate-in .facebook,
.animate-out .facebook{
    @include animation-delay(400ms);
}

关键帧:

$dropHeight:90px;
@include keyframes(dropIn) {
    0% {
          @include transform(  translateY(-$dropHeight) rotate(-20deg) scale(2,4) );

    } 
    100% {
      @include transform( translateY(0px) rotate(0deg) scale(1,1) );
    }
}
@include keyframes(dropShadow) {
    0% {
          @include text-shadow(-$dropHeight $dropHeight 10px rgba($darkBlue,0.2));

    } 
    100% {
      @include text-shadow(0 0 1px darken($darkBlue,3%));
    }
}
@include keyframes(fadeIn) {
    from {
      opacity:0;
    } 
    to {
      opacity:1;
    }
  }
 @include keyframes(fadeOut) {
    from {
      opacity:1;
    } 
    to {
      opacity:0;
    }
  }

我正在使用这个JS来切换按钮:

$('.navbar-toggle').on('click', function() {
  $('div.navbar-collapse.collapse').toggleClass('animate-out').toggleClass('animate-in');
});

然后这是HTML以及:

<button type="button" data-toggle="collapse" data-target=".navbar-collapse" class="navbar-toggle collapsed">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span><span class="icon-bar">
</span><span class="icon-bar"></span>
</button>
<div class="navbar-collapse animate-out collapse" style="height: 133px;">
    <ul class="nav navbar-nav">
       <li class="facebook active"><a href="#about"> <i class="fa fa-facebook"> </i><span class="text-hide">Facebook</span></a></li>
       <li class="twitter"><a href="#"> <i class="fa fa-twitter"> </i><span class="text-hide">Twitter</span></a></li>
       <li class="google-plus"><a href="#contact"> <i class="fa fa-google-plus"> </i><span class="text-hide">Google+</span></a></li>
     </ul>
 </div>

1 个答案:

答案 0 :(得分:0)

您是否尝试使用.fadeIn().fadeOut()

这应该工作而不必编写所有CSS