简体   繁体   English

使用jQuery添加缓动效果

[英]Add ease out effect with jQuery

I need to add an ease effect to the .dropdown div when it becomes visible with jQuery, but I'd be happy to do it with CSS as well. 当使用jQuery显示时,我需要为.dropdown div添加一个缓动效果,但我也很乐意用CSS做到这一点。 Any ideas? 有任何想法吗? Thanks in advance :) 提前致谢 :)

 $('.btn').bind('click', function (){ $(this).parent().next('.dropdown').toggleClass('open'); }); 
 .top, .bottom { background: #333; height: 50px; } .dropdown { height: 50px; position: absolute; color: black; visibility: hidden; } .open { position: relative; visibility: visible; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div class="top"> <button class="btn">Show content</button> </div> <div class="dropdown"> <p>Hidden content</p> </div> <div class="bottom"> </div> 

https://jsfiddle.net/319zd1sg/1/ https://jsfiddle.net/319zd1sg/1/

1 second fade in ( https://jsfiddle.net/nh2fj27g/1/ ). 1秒淡入( https://jsfiddle.net/nh2fj27g/1/ )。

$('.btn').bind('click', function (){
var $dropdown = $(this).parent().next('.dropdown');
$dropdown.hasClass('open') ? $dropdown.toggleClass('open').animate({opacity: 0},1000) : $dropdown.css({opacity: 0}).toggleClass('open').animate({opacity: 1},1000);

}); });

Hope this helps. 希望这可以帮助。

 $('.btn').bind('click', function() { $('#drop').slideDown('slow'); }); 
 .top, .bottom { background: #333; height: 50px; } .dropdown { display: block; color: black; width: 100%; } .drop { display: none; } } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="top"> <button class="btn">Show content</button> </div> <div id="drop" class="drop"> <div class="dropdown"> <p>Hidden content</p> </div> </div> <div class="bottom"> </div> 

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

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