Javascript 单击即可同时设置动画和淡入淡入
以下是我所拥有的:Javascript 单击即可同时设置动画和淡入淡入,javascript,jquery,animation,toggle,fade,Javascript,Jquery,Animation,Toggle,Fade,以下是我所拥有的: <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script> $("#toggle").click(function() { $(this).toggleClass("on"); $("#m_1").fadeToggle(150); }); </script&
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$("#toggle").click(function() {
$(this).toggleClass("on");
$("#m_1").fadeToggle(150);
});
</script>
这是一个菜单,点击后淡入。我想它去从利润率顶部:-80px;到页边距顶部:点击时为80px,点击关闭时为80px,所有这些都是缓慢褪色的
我对编码不是很有经验,如果这看起来很幼稚,我很抱歉。您可以根据on类的状态运行不同的动画 如果愿意,也可以将不透明度切换添加到.animate调用。取决于价值150万美元的时尚潮流;正在做什么
$("#toggle").click(function() {
//run the stop to make sure the animation isnt already running
$(this).stop(true, true)
//fire the animation based on the class state
if ($(this).hasClass('on')) $(this).animate({margin-top : '80px'});
else $(this).animate({margin-top : '-80px'});
//toggle the class
$(this).toggleClass("on");
$("#m_1").fadeToggle(150);
});