IE 8指定背景颜色更改元素行为 [英] IE 8 specifying background-color changes element behavior

查看:163
本文介绍了IE 8指定背景颜色更改元素行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个绝对定位的div,我试图触发mouseenter和mouseleave事件。在IE8 / 7中,div的背景颜色未指定(因此默认为透明),当鼠标跨越div的边界时,mouseenter / leave事件不会触发,只有div中间的某处

I have an absolutely positioned div on which I am trying to trigger mouseenter and mouseleave events. In IE8/7 with the background-color of the div left unspecified (so that it defaults to transparent), the mouseenter/leave events are not firing when the cursor crosses the div's boundary, only somewhere in the middle of the div and when the cursor is over any text within the div.

当我试图通过添加一个背景颜色到div(例如background-color:green)来调试问题时,问题神奇地消失。 div的盒子模型完美地荣誉和mouseenter /离开火如预期。只有当div的背景颜色未指定(或者明确设置为透明)时,它的行为不正确。

When I attempt to debug the problem by adding a background color to the div (e.g. background-color: green), the problem magically goes away. The div's box model is honored perfectly and mouseenter/leave fire as when expected. It's only when the div's background color is left unspecified (or even explicitly set to transparent) that it doesn't behave correctly.

任何想法?

推荐答案

mouseenter和mouseleave不会注册,直到光标到达某物可见。这是不正确的行为,但这是我们正在处理的资源管理器。

The mouseenter and mouseleave are not registering until the cursor hits something visible. This is not correct behavior, but this is Explorer we're dealing with.

两种可能的解决方案:


  1. 在DIV上放一个细边框,匹配后面的任何内容,不会被注意到。 (这不起作用;请参阅注释。 )

  2. 跟踪mousemove事件,并让您的代码确定鼠标何时进入感兴趣的区域。

  3. ;请参阅评论。)将您的背景设为平铺的透明1x1图片。

  1. Put a thin border on the DIV, one that matches whatever is behind it and won't be noticed. (This doesn't work; see the comments.)
  2. Track mousemove events and have your code determine when the mouse has entered the area of interest.
  3. (Added; see the comments.) Make your background a tiled transparent 1x1 image.

编辑:问题:mouseover和mouseout是否显示相同的奇怪行为?

Question: Do mouseover and mouseout show the same weird behavior?

这篇关于IE 8指定背景颜色更改元素行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆