[英]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. 您可以在变量中设置元素的height
并将其用于动画。 Also you need to save toggle
state to having animation without bug. 另外,您需要将toggle
状态保存为没有错误的动画。
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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.