jQuery: Toggle Dropdown Menu Possibility

Deadly 提交于 2019-12-09 06:01:27
$(".current a").mouseenter(function(){
   $(this).siblings("ul").show();
}).mouseleave(function(){
   $(this).siblings("ul").hide();
});

Is this what you want?

Demo: http://jsfiddle.net/rY8zm/

Baz1nga's solution isn't working for me in Opera. The list dies when the cursor transits from the heading to the list - hence the list can be viewed but its links can never be clicked.

You need to take special measures to see the cursor through the transition from element to element. This achieved with a timeout to delay very lightly the hiding of the list; and the canceling of the timeout each time the cursor passes over any element that should keep the list alive.

The code is moderately complex and looks like this:

function hideList($list) {
    clearTimeout($list.data('dropdown').tim);
    return setTimeout(function() {
        $list.stop(true).slideUp('slow');
    }, 125);
}

$("li.current").on('mouseover', "a.heading", function() {
    var $list = $(this).siblings("ul").slideDown('slow');
    clearTimeout($list.data('dropdown').tim);
}).on('mouseout', function() {
    var $list = $(this).children("ul");
    $list.data('dropdown').tim = hideList($list);
}).children("ul").on('mouseover', function() {
    clearTimeout($(this).data('dropdown').tim);
}).on('mouseout', function() {
    var $list = $(this);
    $list.data('dropdown').tim = hideList($list);
}).data('dropdown', {
    tim: null
}).hide();

See fiddle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!