gpt4 book ai didi

Javascript/css/html - 防止 mousedown 禁用悬停

转载 作者:行者123 更新时间:2023-11-28 15:35:30 24 4
gpt4 key购买 nike

<分区>

似乎在浏览器中,javascript 悬停事件在按住鼠标时被禁用,如下例所示:(无需查看代码,只需运行示例即可了解我在说什么。)

* { user-select: none; }
#click, #drag, #hover {
position: absolute;
box-sizing: border-box;
box-shadow: inset 0 0 0 4px rgba(0, 0, 0, 0.3);
text-align: center;
color: #ffffff;
cursor: default;
}
#click {
width: 150px; height: 150px; line-height: 150px;
left: 10px; top: 50%; margin-top: -75px;
background-color: #d00000;
}
#drag {
width: 220px; height: 50px; line-height: 50px;
left: 160px; top: 50%; margin-top: -25px;
background-color: #900000;
}
#hover {
width: 200px; height: 200px; line-height: 200px;
left: 380px; top: 50%; margin-top: -100px;
background-color: #000000;
white-space: nowrap;
}
#hover:after {
content: "This element has hover effects";
position: absolute;
display: inline-block;
color: #909090;
left: 5px; top: -80px;
font-size: 11px;
}
#hover:hover {
background-color: #ffffff;
color: #000000;
}
<div id="click">
Click down here
</div>
<div id="drag">
--> Now drag over this way -->
</div>
<div id="hover">
No hover occurs
</div>

请注意,在释放鼠标按钮的那一刻,悬停事件通常发生在最右侧的 div 上。

如何在按住鼠标时允许任何元素上发生悬停事件?在 css、纯 javascript 或 html 中寻找解决方案。

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