gpt4 book ai didi

javascript - 在鼠标悬停时显示/隐藏 DIV

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:04:55 25 4
gpt4 key购买 nike

我想在图像/链接悬停时显示一个 DIV,我编写了以下代码

   $("#NotificationSummary").hover(
function () {
$("#dvNotifications").slideDown();
},
function () {

$("#dvNotifications").slideUp();
}
);

DIV 在悬停时显示,但是当我移动到 div 时它隐藏了,当鼠标悬停在 div 上时如何阻止它隐藏

请查看演示http://jsfiddle.net/3hqrW/15/

最佳答案

[reedit based on comment] jsfiddle 修改,删除了 css-only 解决方案。诀窍是监视滑动元素的悬停状态并使用超时来允许用户在滑动元素上移动(另请参阅更新的 jsfiddle 中的注释)。

jsfiddle 派生自 OPs jsfiddle @here

使用您的#ids 的悬停功能:

function hover(e){
e = e || event;
var el = e.target || e.srcElement
,showel = $('#dvNotifications')
;
if (!/NotificationSummary/i.test(el.id)) {
showel .attr('data-ishovered',/over/i.test(e.type));
} else {
showel .attr('data-ishovered',false)
}

if (/true/i.test(showel .attr('data-ishovered'))){return true;}

if (/over$/i.test(e.type) && /NotificationSummary/i.test(el.id)){
showel .slideDown();
} else {
setTimeout(function(){
if (/false/i.test(showel .attr('data-ishovered'))) {
showel .slideUp();
showel .attr('data-ishovered',false);
}
}
,200);
}

关于javascript - 在鼠标悬停时显示/隐藏 DIV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11183975/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com