Mouseenter 仅在 IE9 中的透明 div 边框上触发

发布于 2024-12-10 19:44:08 字数 869 浏览 0 评论 0原文

在我的代码中,我有一个 id 为“SIAinfoBox”的 div,根据鼠标当前所在的 div 来加载不同的详细信息。我将以下两个侦听器附加到每个相关的 div:

$(annoDiv).mouseover(function(event){
                event.stopPropagation;
                $('#SIAinfoBox').empty();
                $('#SIAinfoBox').append(details);
                $('#SIAinfoBox').css('visibility','visible');
            });
$(annoDiv).mouseleave(function(event){
                event.stopPropagation;
                $('#SIAinfoBox').empty();
                $('#SIAinfoBox').css('visibility','hidden');
            });

这些 div 没有设置背景颜色,但有 1 像素的纯黑色边框。在 Firefox 中,一切都运行良好。但在 Internet Explorer 中,仅当鼠标位于 div 边框上方时,SIAinfoBox 才会被填充。将其移动到 div 内似乎会触发 mouseleave 事件,并且内容将被删除并隐藏 div。如果我设置背景颜色,它会像预期的那样工作,但是如果没有背景颜色(或透明),它就不起作用。我也尝试过使用 mouseenter 而不是 mouseover,但结果相同。 为什么 InternetExplorer 会出现这样的行为,或者我可以做些什么来实现我目前在 FF for IE 中获得的结果?

In my code, I have a div with id 'SIAinfoBox' that is to be loaded with different details, depending on what div the mouse is currently over. I appended the following two listeners to every relevant div:

$(annoDiv).mouseover(function(event){
                event.stopPropagation;
                $('#SIAinfoBox').empty();
                $('#SIAinfoBox').append(details);
                $('#SIAinfoBox').css('visibility','visible');
            });
$(annoDiv).mouseleave(function(event){
                event.stopPropagation;
                $('#SIAinfoBox').empty();
                $('#SIAinfoBox').css('visibility','hidden');
            });

These divs have no background-color set, but have a 1px solid black border. In Firefox, all works well. But in Internet Explorer, the SIAinfoBox is filled only when the mouse is over the border of the div. Moving it inside the div seems to fire the mouseleave event, and the content is removed and div hidden. If I set a background-color, it works like it is expected to, but with no background-color (or transparent) it does not work. I have also tried using mouseenter instead of mouseover, but with the same results.
Why does InternetExplorer behave like that or what can I do to achieve the results I am currently getting in FF for IE, too?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

纵山崖 2024-12-17 19:44:08

我遇到过类似的 IE 相关问题,例如 - 你可以做一个
透明 png 并将背景设置为“url(images/transparent.png)
重复滚动 0 0 透明” – SmokeyPHP

首先没有找到他的评论,所以我将其移到此处作为答案。可以通过以下链接找到透明图像:

Answer: style="background:url(images /transparent.png) 重复滚动 0 0 透明"

透明 gif: http://www.golivetutor.com/download/spacer.gif

I've had similar IE related issues such as this - you could make a
transparent png and set the background to "url(images/transparent.png)
repeat scroll 0 0 transparent" – SmokeyPHP

Didn't find his comment first so I moved it here as answer. A transparent image can be found with below link:

Answer: style="background:url(images/transparent.png) repeat scroll 0 0 transparent"

Transparent gif: http://www.golivetutor.com/download/spacer.gif

九公里浅绿 2024-12-17 19:44:08

这是一个错误,当背景透明时,元素对事件也是“透明”的。尝试使用“has布局”(例如zoom:1),如果没有帮助,请将背景中的透明gif图像设置为您的元素

It's ie bug, when background is transparent, element "transparent" for events too. Try to use "has layout" (zoom:1 for example), if it won't help, set transparent gif image in background to your element

梦里兽 2024-12-17 19:44:08

我的经验是,应用 css 样式技巧

{
  zoom: 1;
}

在 IE 9 中有效,但在 IE 10 中无效。如果您没有可用的透明 GIF 或 PNG,如其他一些解决方案中提到的,您也可以使用:

{
  background-color: rgba(0, 0, 0, 0.1);
}

请注意,您将需要避免在 IE 8 中应用这种样式,因为它似乎会引起问题。
“rgba”适用于 IE9 及更高版本

I have experienced that applying the css styling trick

{
  zoom: 1;
}

works in IE 9, but not IE 10. If you do not have a transparent GIF or PNG available to use as mentioned in some of the other solutions you can also use:

{
  background-color: rgba(0, 0, 0, 0.1);
}

Note that you will need to avoid applying this style in IE 8 as it seems to cause problems.
"rgba" is available for IE9 and higher.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文