需要側欄功能,但是當您將光標移動到<div id="out_trigger"></div>
的左側時發生了事件警報('遊標移出...')。mouseleave在塊的交集處觸發
現在,當您將鼠標懸停在某個元素el_1,el_2上時,會觸發該事件。這不應該。
https://jsfiddle.net/vkymqd6h/
解決方案已經發現:https://jsfiddle.net/ahpfx551/
需要側欄功能,但是當您將光標移動到<div id="out_trigger"></div>
的左側時發生了事件警報('遊標移出...')。mouseleave在塊的交集處觸發
現在,當您將鼠標懸停在某個元素el_1,el_2上時,會觸發該事件。這不應該。
https://jsfiddle.net/vkymqd6h/
解決方案已經發現:https://jsfiddle.net/ahpfx551/
問題是與你的CSS。這裏是刪除CSS的My fiddle。這是工作的罰款
#out_trigger{
background: red;
height: 100px;
width: 100px;
}
謝謝,但單位必須重疊。 –
雅而不是使用位置:固定在你的CSS。使用其他定位方式。我的猜測是位置:固定導致問題 –
剛剛從鼠標離開改變你的代碼鼠標移開
$("#out_trigger").mouseout(function(){
alert('cursor out from #out_trigger');
});
試試這個
#out_trigger{
background: red;
width: 50px;
height: 100%;
position: fixed;
left: 0;
top: 0;
background-color: blue;
z-index: 2000;
}
#left_sidebar
{
position: fixed;
z-index: 4000;
top: 160px;
left: 0px;
width: 50px;
/* pointer-events: none; */
}
.item
{
opacity: 0.5;
width: 35px;
height: 30px;
cursor: pointer;
color: white;
background-color: green;
transition: all 0.5s;
padding-top: 15px;
padding-left: 5px;
}
.item:hover{
opacity: 1;
}
#sidebar_trigger{
position: fixed;
left: 0;
top: 0;
width: 5px;
height: 100%;
background-color: red;
z-index: 999;
}
這裏是jsfiddle
這裏的問題是與定位和元素的層次結構。 但是,如果你堅持保持相同的結構,你必須繞過left_sidebar
股利。
下面的代碼工作:
$("#out_trigger").mouseout(onMouseOut);
function onMouseOut(event) {
//the original element the event handler was assigned to
var e = event.toElement || event.relatedTarget;
while (e && e.parentNode && e.parentNode != window) {
if (e.parentNode == this || e == this) {
if (e.preventDefault) e.preventDefault();
return false;
}
e = e.parentNode;
}
// mouse event handled here
alert('cursor out from #out_trigger');
}
謝謝你,但層次結構並不重要。一切都簡單得多。 順便說一下,當您將光標懸停在el_1上並將其移動到右側時,您的解決方案無法工作。 –
這裏實際用途代碼:https://jsfiddle.net/v1br4zwy/。 –
理想情況下,'left_sidebar'應該在層次級別的'out_trigger'內。將編輯答案以支持此操作。 – nashcheez
你不應該判斷由他們的英語俄羅斯人,但他們喝伏特加的能力! – nashcheez
對不起,我的英語) –