javascript - 如果鼠标悬停在第一个或第二个 div 上,则保持第二个 div 可见

标签 javascript jquery css html

有两个div; Div A(默认为 display:none)和 Div B(始终可见)。如果鼠标移到 Div B 上,Div A 将如何显示?如果鼠标光标位于 Div A 或 Div B 上,Div A 应保持可见,否则 Div A 应隐藏。

为此,我正在使用 jQuery 插件 hoverIntent。

$(".the-dropdown").hoverIntent( function(){
        $(".the-dropdown").show();
    }, function(){
        $(".the-dropdown").hide();
});

$(".menu-item").hoverIntent( function(){
    $(".the-dropdown").show();
}, function(){
    $(".the-dropdown").hide();
});

jsfiddle

最佳答案

嗯,试试这样的东西。

HTML:

<div id="a"></div>
<div id="b"></div>

CSS:

div {
    height: 200px;
    width: 200px;
}
#a {
    background: #0f0;
    display: none;
}
#b {
    background: #f0f;
}

JS:

$('#a, #b').hover(function() {
    $('#a').show(); 
}, function() {
    $('#a').hide();    
});

Fiddle

或者在您的具体情况下:

$(".the-dropdown, .menu-item").hover( function(){
        $(".the-dropdown").show();
    }, function(){
        $(".the-dropdown").hide();
});

关于javascript - 如果鼠标悬停在第一个或第二个 div 上,则保持第二个 div 可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18882876/

相关文章:

javascript - 视频播放完毕后,播放按钮不会开始播放视频

html - 为什么aspectraio 不适用于Flexbox 子项?

javascript 错误 "is not a function..."但已加载库

javascript - 输入文本输入触发按钮点击

jquery - 显示隐藏的 div 时停止页面滚动

javascript - 是否有一个 UI 框架来模拟 Mac 应用程序的外观?

javascript - 为什么 Jest 测试中不调用此函数?

javascript - 如何设置Node.js错误处理?

javascript - ES6/2015 中的空安全属性访问(和条件赋值)

php - slider 中图像之间的空白空间