悬停、悬停、选中
$('#box_1, #box_2, #box_3, #box_4').hover(function() {
$(this).addClass('hover');
}, function() {
$(this).removeClass('hover');
});
但是当我点击“HOVER
”class = .removeClass('hover')
时,
无论如何要在我点击时保留这个“HOVER
”类吗?
http://jsfiddle.net/EAa6p/ (这是我的原创)
完成!通过本<3 http://jsfiddle.net/EAa6p/1/ 谢谢大家
$('#box_1, #box_2, #box_3, #box_4').hover(function() {
$(this).addClass('hover');
}, function() {
$(this).removeClass('hover');
});
But when I clicked, "HOVER
" class = .removeClass('hover')
Anyway to stay this "HOVER
" class when I clicked ?
http://jsfiddle.net/EAa6p/ (This is my original)
DONE ! by Ben <3
http://jsfiddle.net/EAa6p/1/
Thanks you all
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我认为您的意思是在单击发生时保留悬停类。
最好的选择是使用 data() 保存状态并检查悬停
是否是您想要的通缉?
http://jsfiddle.net/uhc9S/
I think you mean to persist the hover class when a click occur.
The best option is to use data() to save the state and check on the hover out
Is that what you wanted?
http://jsfiddle.net/uhc9S/
CSS:将
.hover{...}
规则更改为JavaScript/jQuery:不要在悬停时添加悬停类,并在取消悬停时将其删除。相反,CSS 将处理悬停,而 jQuery 只需处理点击:
:hover
规则意味着它处于悬停状态。当您希望它在单击后看起来悬停时,将使用.hover
规则。CSS: Change your
.hover{...}
rule toJavaScript/jQuery: Don't add the hover class on hover and remove it on unhover. Instead, CSS will handle hover and jQuery just has to handle click:
The
:hover
rule means it is hovered. The.hover
rule will be used when you want it to look hovered after it is clicked.使用鼠标悬停和鼠标悬停
Use mouseover and mouseout
保留一个变量,其中包含单击的菜单项的 id
Keep one variable which contains the id of the menuitem clicked
http://jsfiddle.net/hRnQE/
单击时,切换另一个执行相同操作的“不同”类...
js
css
http://jsfiddle.net/hRnQE/
on click, toggle another 'different' class that does the same thing...
js
css