Mouseenter 仅在 IE9 中的透明 div 边框上触发
在我的代码中,我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先没有找到他的评论,所以我将其移到此处作为答案。可以通过以下链接找到透明图像:
Answer: style="background:url(images /transparent.png) 重复滚动 0 0 透明"
透明 gif: http://www.golivetutor.com/download/spacer.gif
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
这是一个错误,当背景透明时,元素对事件也是“透明”的。尝试使用“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
我的经验是,应用 css 样式技巧
在 IE 9 中有效,但在 IE 10 中无效。如果您没有可用的透明 GIF 或 PNG,如其他一些解决方案中提到的,您也可以使用:
请注意,您将需要避免在 IE 8 中应用这种样式,因为它似乎会引起问题。
“rgba”适用于 IE9 及更高版本。
I have experienced that applying the css styling trick
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:
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.