简体   繁体   中英

jquery how to toggle this specific animation?

所以我想在jQuery中切换此动画,但是我发现很难找到一种方法。

$( "#console" ).animate({height: "20px"});

You can set height of element in variable and use it to animate. Also you need to save toggle state to having animation without bug.

 var firstHeight = $("div").height(); $("div").click(function(){ $(this).stop(); if (!$(this).data("animateToggle")) $("div").data("animateToggle", 1).animate({height: "200px"}); else $("div").removeData("animateToggle").animate({height: firstHeight}); }); 
 div { width: 100px; height: 100px; background: green; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div></div> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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