admin管理员组文章数量:1384482
I have one large div with one smaller div inside it. The smaller div is at first displayed as hidden. When the user hovers the mouse over the large container-div the smaller div is animated in with the show/hide-functions. So far everything works fine.
However. The smaller div is animated in from the bottom - so if I let the cursor hover over the container at the very bottom, it's hovering over the animation of the smaller div while it's sliding in. So now the cursor is hovering over the smaller div instead of the larger div, and thus triggering the hide-function on the smaller div. This creates an infinite loop of show/hide calls as the smaller div slides in and out of where the cursor is pointing.
Any ideas how to avoid this and not break the hovering on the container as the smaller div enters?
This is what I mean:
alt text .jpg
I have one large div with one smaller div inside it. The smaller div is at first displayed as hidden. When the user hovers the mouse over the large container-div the smaller div is animated in with the show/hide-functions. So far everything works fine.
However. The smaller div is animated in from the bottom - so if I let the cursor hover over the container at the very bottom, it's hovering over the animation of the smaller div while it's sliding in. So now the cursor is hovering over the smaller div instead of the larger div, and thus triggering the hide-function on the smaller div. This creates an infinite loop of show/hide calls as the smaller div slides in and out of where the cursor is pointing.
Any ideas how to avoid this and not break the hovering on the container as the smaller div enters?
This is what I mean:
alt text http://archivedworks./fileserver/jQuery_hover_showhide.jpg
Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Apr 7, 2010 at 18:53 o01o01 5,45012 gold badges48 silver badges87 bronze badges 2-
Are you using
.hover()
or.mouseXX
events to bind the event handler? – Nick Craver Commented Apr 7, 2010 at 19:05 - I used the method in the answer marked as the solution. Ergo the .hover() event. – o01 Commented Apr 7, 2010 at 23:58
2 Answers
Reset to default 6You can do it like this:
$("#outerDiv").hover(function() {
$("#innerDiv:hidden").slideDown(); //your show code
}, function() {
$("#innerDiv:visible").slideUp(); //your show code
});
This only queues a hide animation if it's visible (:visible
), and only queues a show animation if it's not (:hidden
), preventing the queue/loop behavior you have now.
$('#idOfLargeDiv').hover(
function() {
$('#idOfSmallDiv').slideDown();
},
function() {
$('#idOfSmallDiv').slideUp();
}
);
本文标签: javascriptjQuery slide updown on hover bugStack Overflow
版权声明:本文标题:javascript - jQuery slide updown on hover bug - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744536846a2611368.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论