覆盖 jQuery 中的伪样式
如何使用 jQuery 覆盖下面的 CSS?
(动画没有运行,只是瞬时切换。)
menu span ul {display: none;}
menu span:hover ul {display: block;}
$('#menu span').mouseenter(function(){
$('#menu span ul').slideDown('fast');
}).mouseleave(function(){
$('#menu span ul').slideUp('fast');
});
How can I overwrite the CSS below with jQuery?
(The animations aren't being run and it's just an instantaneous switch.)
menu span ul {display: none;}
menu span:hover ul {display: block;}
$('#menu span').mouseenter(function(){
$('#menu span ul').slideDown('fast');
}).mouseleave(function(){
$('#menu span ul').slideUp('fast');
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
优雅降级的一个技巧是不必覆盖样式,如下所示:
以与所有这些非 JS 用户样式相同的方式拥有一个链接样式表。
或者,通过您应用于
#menu
的类来执行此操作,您可以将其删除,以便规则不再匹配,如下所示:在您的脚本中,只需删除该类:
作为旁注,您可以 slim使用
.hover()
和.slideToggle()
像这样:One trick for graceful degredation is to not have to override the styles, like this:
Of have a linked stylesheet the same way with all of these for-non-JS-user styles.
Or, do it via a class you apply to
#menu
that you can remove so the rules no longer match, like this:And in your script just remove that class:
As a side note, you can slim down your code using
.hover()
and.slideToggle()
like this:您看不到动画,因为您的 css 覆盖了它。
删除
我不会费心尝试覆盖 css 以适应未启用 js 的浏览器。这个数字太小了,不值得考虑。
You're not seeing the animation because your css is overriding it.
Remove
I wouldn't bother trying to override the css to accommodate browsers that don't have js enabled. The number is so small that it isn't worth consideration.