我想为我的下拉菜单添加 CSS3 效果。 (就像 Instagram.com 中“我的个人资料”中的那个)。
我正在使用 Animate.css用于 CSS3 效果。
我试过了,但是没用。
HTML
<a href="#" data-dropdown="dropdownalerts" data-options="is_hover:true"><%=fa_icon "bell"%></a>
<ul id="dropdownalerts" class="f-dropdown text-left animated bounceInDown" data-dropdown-content>
<li><%=link_to "Facebook", "#"%></li>
<li><%=link_to "Email", "#" %></li>
</ul>
JS
$(document).ready(function(){
$('a').hover(function(){
$("ul").addClass('animated bounceInDown');
});
});
您可以在 Zapping.io 上找到实时版本
最佳答案
我让它在一个例子中工作。我使用了您提供的 HTML,然后下载了 bounceInDown
动画并将其用于以下示例中的 CSS。
jsFiddle example here - 悬停方法
jQuery
$(document).ready(function(){
$('a').hover(function() {
$("ul").addClass('animated bounceInDown');
},function(){
$("ul").removeClass('animated bounceInDown');
});
});
如果你想在悬停时添加延迟,使用这样的东西:
jsFiddle example - 具有延迟的悬停方法。
$(document).ready(function(){
$('a').hover(function() {
$("ul").addClass('animated bounceInDown');
},function(){setTimeout(function(){
$("ul").removeClass('animated bounceInDown');
}, 750);});
});
这些示例假设您希望在悬停时触发动画。如果您希望它在点击时触发,请改用这样的东西:
jsFiddle example单击方法 - 在下面查找替代的非 JS 方法。
$(document).ready(function(){
$('a').click(function() {
$("ul").toggleClass('animated bounceInDown');
});
});
替代方法 - 无 JS/jQuery
如果您不想使用 JavaScript/jQuery,您可以使用 CSS 中的复选框 hack。
这实质上是在 :checked
之间切换,从而激事件画。
jsFiddle example - 它适用于所有当前的浏览器。
HTML
<label id="click" for="dropdown">Click here</label>
<input style="display:none" type="checkbox" id="dropdown">
<ul id="dropdownalerts" class="f-dropdown text-left" data-dropdown-content>
<li>Facebook</li>
<li>Email</li>
</ul>
CSS - (只是其中的一部分)完整 CSS 参见上面的示例。
input[type=checkbox]:checked ~ #dropdownalerts {
display:inline-block;
-webkit-animation: bounceInDown 1s both;
-moz-animation: bounceInDown 1s both;
-o-animation: bounceInDown 1s both;
animation: bounceInDown 1s both;
}
关于css - 如何使用 CSS3 动画为下拉菜单设置动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20468761/