简体   繁体   English

jQuery的CSS3动画

[英]CSS3 animation with jQuery

This one is a bit of a long shot but here goes - I'm new to css3 animation so please bare with.. 这个有点远,但是可以了-我是css3动画的新手,所以请裸手。

Codepen link Codepen链接

  $(document).ready(function(){ $("#menu").mmenu({ extensions : [ "theme-dark", "effect-slide-menu", "effect-slide-listitems" ], iconPanels : { add : true, visible : 1, hideNavbars : true } }) $("#hamburger").click(function(){ $(".burger .one, .burger .two, .burger .three, .circle").css("-webkit-animation-play-state", "running"); }); }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jQuery.mmenu/5.3.1/js/jquery.mmenu.min.all.js"></script> <link href="https://cdnjs.cloudflare.com/ajax/libs/jQuery.mmenu/5.3.1/css/jquery.mmenu.all.css" rel="stylesheet"/> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="page"> <div class="header"> <a href="#menu" id="hamburger"> <div class="burger"> <div class="one"></div> <div class="two"></div> <div class="three"></div> </div> <div class="circle"></div> </a> Demo </div> <div class="content"> <p><strong>This is a demo.</strong><br /> Click the menu icon to open the menu.</p> </div> </div> <!-- The page End--> <!-- The menu --> <nav id="menu"> <ul> <li><a href="/">Home</a></li> <li><a href="/about">About us</a> <ul> <li><a href="/about/history">History</a></li> <li><a href="/about/team">The team</a></li> <li><a href="/about/address">Our address</a></li> </ul> </li> <li><a href="/contact">Contact</a></li> </ul> 

When the hamburger menu opens the animation starts on the icon but then when you close it the animation stays at the open state. 当汉堡菜单打开时,动画从图标开始,但是当您关闭它时,动画保持在打开状态。 I want it to return to the original state 我希望它恢复到原始状态

Thanks in advance 提前致谢

Use the mousedown event of the mm-blocker to reset the previous style. 使用mm-blocker的mousedown事件可重置以前的样式。 I used animation direction reverse to do it. 我使用动画方向反转来做到这一点。 Here's the codepen http://codepen.io/anon/pen/gpoPqQ 这是codepen http://codepen.io/anon/pen/gpoPqQ

     $("#mm-blocker").on( "mousedown",function(){
     $(".burger .one, .burger .two, .burger  .three, .circle").css("-webkit-animation-direction", "normal");
    } );


        $("#hamburger").click(function(){
        $(".burger .one, .burger .two, .burger  .three, .circle").css("-webkit-animation-direction", "reverse");
        $(".burger .one, .burger .two, .burger  .three, .circle").css("-webkit-animation-direction", "running");

       });

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

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