jQuery Dropdown queue buildup
I have created a drop down with jQuery that can be seen here by clicking the Preview button on top:
var open_submenu = null;
$(function(){
$('.dropdown').hover(function(){
// hide all previous submenus and fix queue buildup problem
$('.sublinks').stop(false, true).hide();
// get corresponding submenus
var submenu = $(this).parent().next();
$(this).parent().nextAll().stop();
$(submenu).css({
top: $(this).offset().top + $(this).height() + 4 + 'px',
left: $(this).offset().left + 'px',
zIndex:10000
});
// show the submenu
开发者_C百科 $(submenu).stop().slideDown(300);
open_submenu = submenu;
submenu.hover(function(){}, function(){
$(this).slideUp(300);
});
}, function(){});
});
http://jsbin.com/ubire3/edit
It works fine except for one problem. When I hover over the main hover links (blue ones) quickly eg. going horizontally quickly hovering each top menu, the some submenus don't close. How do I make it so that even if I hover fast over them all other submenus are closed?
Edit
I saw this useful link using some ways to avoid this, but having bit of problems, how to apply that in my case.
What are queues in jQuery?
Great, finally I solved the problem myself:
All I did was to modify the line:
$('.sublinks').hide();
to
$('.sublinks').stop(false, true).hide();
The stop
stopped animations for previous sub-menus. You can see the documentation of it on the jQuery site.
See fixed version here:
http://jsbin.com/ubire3/5/edit
Fixed it here: http://jsbin.com/ubire3/3
I don't know why my changes were not reflected @ above link
See it here
i am not using stop
method
精彩评论