繁体   English   中英

下拉选项在jQuery中不起作用

[英]Drop down option not working in jQuery

我正在尝试在鼠标悬停和单击时构建下拉选项。 我唯一的问题是,当我将鼠标放在on子元素上时,菜单会快速隐藏。

jQuery代码:

var navPos = $("#topNav").position().top; // ignore this line
// menu drop options
$('.repeat, .recitor, .volume, .bandwidthOption').bind('dropOption', function(e, force) {
    var force = force || 'toggle';

    if ($(this).hasClass('repeat'))
        var optionName = 'repeat';
    else if ($(this).hasClass('recitor'))
        var optionName = 'recitor';
    else if ($(this).hasClass('volume'))
        var optionName = 'volume';
    else if ($(this).hasClass('bandwidthOption'))
        var optionName = 'bandwidthOption';
    else
        return;

    var optionSubName = $(this).find('ul').attr('class');
    var position = $(this).position();
    position.top = navPos;
    var isActive = $(this).hasClass('active');

    if ((isActive && force != 'show') || (force && force == 'hide'))
    {
        $(this).removeClass('active');
        $('.'+optionSubName).hide();
        if (optionName == 'recitor') /* ie fix - z-index issue */
            $('.logoBox').show();
    }
    else
    {
        $(this).addClass('active');
        $('.'+optionSubName).show();
        $('.'+optionSubName).css('left',position.left+'px');
        if (optionName == 'recitor') /* ie fix - z-index issue */
            $('.logoBox').hide();
    }
});
$('.repeat, .recitor').click(function() {
    $(this).trigger('dropOption');
    return false;
});
$('.volume, .bandwidthOption').hover(function() {
    $(this).trigger('dropOption', 'show');
},function() {
    $(this).trigger('dropOption', 'hide');
});

菜单演示: http : //jsbin.com/ozokir/2

最后一点是隐藏选项:

$('.volume, .bandwidthOption').hover(function() {
    $(this).trigger('dropOption', 'show');
},function() {
    $(this).trigger('dropOption', 'hide');
});

悬停仅在链接选项上。 要解决这个问题,您可以使用:

$('.volume, .bandwidthOption').mouseover(function() {
        $(this).trigger('dropOption', 'show');
    });

或像上一行一样单击。 然后,您可以隐藏:

$('.dropOption').mouseout(function() {
            $(this).trigger('dropOption', 'hide');
        });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM