我正在尝试为这样的类添加高亮颜色
$(".common_box").hover(function(){ $(".common_box").addClass("hover_me"); });这有效,但为什么不这样做
$(".common_box").hover(function(){ $(".common_box").toggleClass("hover_me"); });当我将鼠标悬停在此时没有任何反应
当他们离开悬停时,是否没有移除来删除班级hover_me
I am trying to add a highlight color to a class like this
$(".common_box").hover(function(){ $(".common_box").addClass("hover_me"); });this works but why doesnt this
$(".common_box").hover(function(){ $(".common_box").toggleClass("hover_me"); });when i hover over this nothing happens
is there no unhover to put to remove the class hover_me when they move away from the hover
最满意答案
在某些情况下,鼠标进入/离开事件发生了两次,这是有效的,所以它正在工作,但它是每次进/出的双重切换,所以没有净效果......现在,为了安全起见:
$(".common_box").hover(function(){ $(this).addClass("hover_me"); }, function(){ $(this).removeClass("hover_me"); });这是一个错误(我相信 ),因为.live()更改支持.hover() ,这会导致一些不必要的副作用,你可以像上面那样明确100%安全,所以如果每个处理程序运行多个时间,至少为了你的目的,没关系。
There's currently a bug in some situations where the mouse enter/leave events are firing twice, so it is working, but it's double toggling each in/out, so no net effect...for now, to be safe:
$(".common_box").hover(function(){ $(this).addClass("hover_me"); }, function(){ $(this).removeClass("hover_me"); });This is a bug (I believe) because of the .live() changes to support .hover(), which is causing some unwanted side-effects, you can be explicit like above to be 100% safe, so if each handler runs multiple times, at least for your purposes, it's alright.
更多推荐
发布评论