jQuery 将鼠标悬停在父级上而不是子级上
无论如何,是否可以使用 jQuery 与 DOM 进行交互,当用户将鼠标悬停在 div 上时,会出现一个菜单,但是当他们将鼠标悬停在该父元素内的特定子元素上时,什么也没有发生?
到目前为止的代码
$('#player_area:not(< #player_links)').live("mouseenter", function() {
return $('#album_tracks').slideDown(200);
}).live("mouseleave", function() {
return $('#album_tracks').hide();
});
Is there anyway to interact with the DOM using jQuery that when a user hovers over a div a menu appears, but when they hover over a particular child element inside that parent, nothing happens?
Code so far
$('#player_area:not(< #player_links)').live("mouseenter", function() {
return $('#album_tracks').slideDown(200);
}).live("mouseleave", function() {
return $('#album_tracks').hide();
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是您需要的: http://api.jquery.com/mouseover/
mouseenter
和mouseleave
方法。检查示例演示;)
Here is what you need : http://api.jquery.com/mouseover/
mouseenter
andmouseleave
method.Check the example demo ;)
问题是这是否是因为您不希望在子项上使用 mouseenter 事件重复该操作。也就是说,该事件已经由父级触发,并且您不希望在没有先离开父级的情况下再次执行该事件,或者您是否希望子级不触发 mouseenter(如果它已位于父级之外)。
如果您仅删除 :not 选择器,您的代码似乎应该可以工作。
编辑...抱歉误解了...以下小提琴应该解决您需要执行的操作
http://jsfiddle.net /q4beS/6/
The question is whether it is because you do not wish the action to be repeated with mouseenter events on the children. That is the event is already triggered by the parent and you don't want it to be performed again without first leaving the parent or whether you want the child to not trigger the mouseenter (if it has been positioned outside of the parent).
It seems that your code should work if you merely remove the :not selector.
Edit... Sorry misunderstood... The following fiddle should address what you needed to do
http://jsfiddle.net/q4beS/6/