简体   繁体   English

显示的mouseover事件:无(隐藏)元素(Chrome和Opera)

[英]mouseover event on display:none (hidden) element (chrome & opera)

In brief: display:none element gets mouseover event when i click a select menu that overlaps display:none element. 简而言之:当我单击与display:none元素重叠的选择菜单时,display:none元素将获得鼠标悬停事件。

code summary: A ul above a select element. 代码摘要:select元素上方的ul。 ul has all but top li as display:none. ul除了top li外,几乎没有显示:none。 Via JS, lower li's become display:block when you mouseover the displayed ul. 通过JS,当您将鼠标悬停在显示的ul上时,下li变为display:block。 On mouseout, lower li's become hidden again. 移出鼠标后,小李又再次隐藏起来。 (Its a hover and expand feature you may know for navigation.) (它是您可能需要导航的悬停和扩展功能。)

Expected behavior: Show top li only. 预期行为:仅显示top li。 Hover it and show all li's (full ul shown). 悬停它并显示所有li的(显示完整的ul)。 Mouseout of ul and hide all but top li. 将ul移出并隐藏除top li以外的所有内容。 (You can mouse around whole ul once its shown and you dont get mouseout event. (一旦显示整个ul,您就可以对其进行鼠标移动,而不会发生mouseout事件。

Problem: I have a select dropdown right below the ul. 问题:我在ul下方有一个选择下拉列表。 Clicking select makes ul display. 单击选择将显示ul。 (Your cursor is now hovering the expanded ul.) This happens in chrome 36.0.1985.125 and Opera 21.0.1432.67. (您的光标现在悬停在扩展的ul上。)在chrome 36.0.1985.125和Opera 21.0.1432.67中会发生这种情况。 Does NOT happen in firefox 29.0.1. 在Firefox 29.0.1中不会发生。 Here is the code as simple as i can make it. 这是我能做到的简单代码。 Click the last select option and see. 单击最后一个选择选项,然后查看。

Question: What's the bug/unexpected behavior. 问题:什么是错误/意外行为。 Can i prevent this? 我可以预防吗?

<style type="text/css">
ul{
    font-size:150%;
    margin: 0px;
    padding:0px;
}
select{
    display:inline;
}
</style>

<script type="text/javascript">
function show(name1,name2,name3,name4){
    document.getElementById(name1).style.display="block";
    document.getElementById(name2).style.display="block";
    document.getElementById(name3).style.display="block";
    document.getElementById(name4).style.display="block";
}
function hide(name1,name2,name3,name4){
    document.getElementById(name1).style.display="none";
    document.getElementById(name2).style.display="none";
    document.getElementById(name3).style.display="none";
    document.getElementById(name4).style.display="none";
}
</script>

<ul onmouseover="show('id1','id2','id3','id4')" onmouseout="hide('id1','id2','id3','id4')">
    <li>asdf1</li>
    <li style="display:none" id="id1">asdf2</li>
    <li style="display:none" id="id2">asdf3</li>
    <li style="display:none" id="id3">asdf4</li>
    <li style="display:none" id="id4">asdf5</li>
</ul>
<br>
<select>
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
</select>

This is an issue with Chromium: https://code.google.com/p/chromium/issues/detail?id=389163 . Chromium出现此问题: https : //code.google.com/p/chromium/issues/detail? id =389163 Unfortunately, there is no easy fix. 不幸的是,没有容易解决的方法。

try to bind onmouseover event in <li> 尝试在<li>绑定onmouseover事件

<ul onmouseout="hide('id1','id2','id3','id4')">
    <li onmouseover="show('id1','id2','id3','id4')">asdf1</li>
    <li style="display:none" id="id1">asdf2</li>
    <li style="display:none" id="id2">asdf3</li>
    <li style="display:none" id="id3">asdf4</li>
    <li style="display:none" id="id4">asdf5</li>
</ul>

I tested your code but not found the effect you described. 我测试了您的代码,但没有发现您描述的效果。
firstly,ul is block element and elements of display:none are disappeared in the window,clicking select won't enter ul's boundary unless you made wrong layout. 首先,ul是块元素,而display元素:窗口中不会消失,单击select不会输入ul的边界,除非您进行了错误的布局。
If this condition will happen in your choosing select's <option> ,you should prevent select's <option> get across <ul> . 如果在选择select的<option>会发生这种情况,则应防止select的<option>碰到<ul>

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

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