空 div 悬停事件在 IE 中未触发

发布于 2024-08-20 01:12:31 字数 1465 浏览 10 评论 0原文

我有一个 div,里面有一个子 div。当鼠标悬停在父 div 上时,我使用 jQuery 显示/隐藏子 div(父 div 跨越页面的整个底部。宽度:100%,高度 100px)。我使用了 firebug 和 ie 开发人员工具栏来确认父 div 位于页面上。

我可以将鼠标悬停在 Chrome 和 FireFox 中的空父 div 上,一切正常。 IE 要求我在里面有某种文本来悬停。仅使用空 div 时不会触发 div 悬停事件。

此问题的所有可行的解决方法?

--更新

尝试了您的所有建议,但还没有任何效果。

<div id="toolBar">          
  <div>
    <button id="btnPin" title="Click to pin toolbar" type="button">
      <img id="pin" src="../../images/icons/unpin.png" alt="Pin" /></button>
      <img src="../../images/icons/search.png" border="0" alt="Search" />
  </div>
</div>

上面的 html 包含在母版页 div 容器中。子 div 通过 jQuery 隐藏,并带有一些悬停输入/输出事件。父 div (toolBar) 在页面上始终可见。当鼠标悬停在工具栏上时,会显示子 div。

这是 jQuery 代码

$('#toolBar').hover(ToolBar_OnHover, ToolBar_OnBlur);

function ToolBar_OnHover() {

  $(this).children().fadeIn('fast');
  $(this).animate({ height: "100px" }, "fast");

}

function ToolBar_OnBlur() {

  $(this).children().fadeOut('fast');
  $(this).animate({ height: "50px" }, "fast");

}

最后是一些 css

#toolBar { width: 100%; height: 100px; text-align:center; vertical-align:middle; position: absolute;  bottom: 0; background-color: Transparent;  }
#toolBar div { padding: 5px 5px 0px 5px; width:75%; height: 95px; background: transparent url('/images/toolbar-background.png') repeat-x; margin-right: auto; margin-left: auto; }

I have a div with a child div inside it. I'm using jQuery to show / hide the child div whenever a mouse hovers over the parent div (parent div spans the entire bottom of the page. Width: 100% and height 100px). I've used both firebug and ie developer toolbar to confirm that the parent div is on the page.

I can hover over the empty parent div in both Chrome and FireFox and everything works fine. IE requires that I have some sort of text inside to hover over. The div hover event will not fire with just an empty div.

All plausible work arounds for this issue?

--Update

Tried all of your suggestions but nothing has worked yet.

<div id="toolBar">          
  <div>
    <button id="btnPin" title="Click to pin toolbar" type="button">
      <img id="pin" src="../../images/icons/unpin.png" alt="Pin" /></button>
      <img src="../../images/icons/search.png" border="0" alt="Search" />
  </div>
</div>

The above html is contained within a master page div container. The child div is hidden with jQuery with some hover in/out events. The parent div (toolBar) is always visible on the page. When a hover occurs on toolBar the child div is shown.

Heres the jQuery code

$('#toolBar').hover(ToolBar_OnHover, ToolBar_OnBlur);

function ToolBar_OnHover() {

  $(this).children().fadeIn('fast');
  $(this).animate({ height: "100px" }, "fast");

}

function ToolBar_OnBlur() {

  $(this).children().fadeOut('fast');
  $(this).animate({ height: "50px" }, "fast");

}

Finally here's a little css

#toolBar { width: 100%; height: 100px; text-align:center; vertical-align:middle; position: absolute;  bottom: 0; background-color: Transparent;  }
#toolBar div { padding: 5px 5px 0px 5px; width:75%; height: 95px; background: transparent url('/images/toolbar-background.png') repeat-x; margin-right: auto; margin-left: auto; }

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

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

发布评论

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

评论(13

心是晴朗的。 2024-08-27 01:12:31

如果您设置背景颜色或边框,它将起作用...

如果您可以将其中任何一个与现有外观相匹配,那么您就可以了..

背景图像似乎就像最不引人注目的解决方案

it will work if you set a background-color or a border ...

if you could match either of these with the existing look then you would be ok..

(a background-image seems like the most unobtrusive solution)

如何视而不见 2024-08-27 01:12:31

任何评论和过滤器都不适合我。
div 永远不会被渲染,因此不可能悬停。

最终解决方案:

.aDiv {
    background: transparent url(../images/transparent.gif) repeat;
}

使用一像素透明 gif 图像。当然可以!

None of comments and filters stuff works for me.
The div is never rendered, so no hover possible.

Ultimate solution:

.aDiv {
    background: transparent url(../images/transparent.gif) repeat;
}

With a one pixel transparent gif image. Sure it works !

明媚殇 2024-08-27 01:12:31

我知道问题已经得到解答,但我遇到了同样的问题。空的 div 不会触发该函数。如果它有边框,则只有边框本身才会启动该功能。我尝试了很多东西,但没有任何帮助。这是我的解决方案,几乎相同,唯一的问题是我没有使用图像。
将其添加到您的 CSS 中:

div {             /* write the element's name, class or id here */
background: #FFF; /* you can choose any colour you like, 1.0-fully visible */
opacity:0.0;      /* opacity setting for all browsers except IE */
filter: alpha(opacity = 0); /* opacity setting for IE, 0-transparent & 100-fully visible */
}

I know that the question has been answered but I encountered the same problem. The empty div wouldn't fire the function. And if it had a border only the border itself would start the function. I tried lots of stuff, nothing helped. Here is my solution, it's pretty much the same only thing is that I didn't use an image.
Add this to your CSS:

div {             /* write the element's name, class or id here */
background: #FFF; /* you can choose any colour you like, 1.0-fully visible */
opacity:0.0;      /* opacity setting for all browsers except IE */
filter: alpha(opacity = 0); /* opacity setting for IE, 0-transparent & 100-fully visible */
}
樱花坊 2024-08-27 01:12:31

如果你想保留你的 DIV 这对我有用:
背景颜色:rgba(0,0,0,0.001);

If you want to preserve your DIV this worked for me:
background-color: rgba(0,0,0,0.001);

铃予 2024-08-27 01:12:31

@Skateball:该解决方案有效,但也隐藏了 FF/chrome 中的任何子元素。这是我的看法:

background:#000;
background:rgba(0,0,0,0);
filter:alpha(opacity=0);

@Skateball: that solution works, but also hides any child elements in FF/chrome. Here is my take:

background:#000;
background:rgba(0,0,0,0);
filter:alpha(opacity=0);
晚雾 2024-08-27 01:12:31

这有点 hacky,我不知道它是否会改变布局,但你总是可以在 div 中放置一个  

It's kind of hacky, and I don't know if it'll change the layout, but you could always just put an   inside the div.

老娘不死你永远是小三 2024-08-27 01:12:31

只需在“空”元素中插入一个空注释即可。 :)

<div><!-- --></div>

这将强制 IE 渲染该元素

Just insert an empty comment inside the "empty" element. :)

<div><!-- --></div>

This'll force IE to render the element

遥远的她 2024-08-27 01:12:31

可能是 hasLayout 标志该元素需要被强制。
这可以通过对其应用 CSS 属性 zoom:1 来完成。

It might be that the hasLayout flag of the element needs to be forced.
This can be done by applying the CSS property zoom:1 to it.

不如归去 2024-08-27 01:12:31
.trasnparentIE
{
    background: url(../images/largeTransparent.gif) repeat;
}

当我添加边框时,悬停事件仅在鼠标位于或非常接近边框时触发,但我不需要边框,所以我只使用透明背景,它对我有用...透明背景对我有用(评论和nbsp也不起作用......)

.trasnparentIE
{
    background: url(../images/largeTransparent.gif) repeat;
}

when I added the border the hover event only fired when the mouse was over or very close to the border but i dont need the border so i just use of transparent background and it works for me ... the transparent background did the trick for me (comments and nbsp didn't work either...)

一指流沙 2024-08-27 01:12:31

您只需设置不透明度即可使图层不可见,并且还应该设置背景

{
    background: white;
    opacity: 0;
}

You just can set opacity to make layer invisible and you should also set background

{
    background: white;
    opacity: 0;
}
妞丶爷亲个 2024-08-27 01:12:31

我发现将鼠标事件跟踪 div 浮动在某个区域上的最佳方法是使 div 宽度为 1px,高度为您需要的高度。然后给div一个你需要的实际宽度的透明右边框。这比透明图像效果更好的原因是,如果您使用图像,则无法跟踪鼠标移动事件,例如拖动,而 div 不会失去焦点(您将拖动图像)。当使用 jQuery UI 滑块或鼠标拖动来擦除动画时,我遇到了这个问题。这是我的代码的简单版本。

//container div to hold the animation images this part doesn't really matter to answer the question
<div style="position:absolute; left:0px; top:0px; width:200px; height:200px">
// a bunch of images stacked like one of those animation flip books you made when you were a kid
   <img id="image01" src="blah01.jpg" />
   <img id="image02" src="blah01.jpg" />
   <img id="image03" src="blah01.jpg" />
   // and so on
</div>
//
// now the div that tracks the mouse events this is what I am describing to answer the question
// it could certainly be used above nav items and would have less load time than an image
<div style="position:absolute; left:-1px; top:0px; width:1px; height:200px; border-right: solid 200px transparent; />

在我的应用程序中,鼠标每向左或向右移动 2 px,我就会提供适当的图像可见性,同时隐藏所有其他图像,宾果游戏你就有了一个动画。 (空 div 在所有非 IE 浏览器中都能正常工作,但这在 IE 和非 IE 中都有效,因此无需以两种方式编写它。)

I found the best way to float a mouse event tracking div over an area is to make the div 1px width and what ever height you need. Then give the div a transparent border-right of the actual width you need. The reason this works better than a transparent image is because if you use an image you then cannot track mousemove events, for example to drag, without the div losing focus (you instead will drag the image). I had this issue when both a jQuery UI slider or a mouse drag were used to scrub an animation. Here is a simple version of how my code looked.

//container div to hold the animation images this part doesn't really matter to answer the question
<div style="position:absolute; left:0px; top:0px; width:200px; height:200px">
// a bunch of images stacked like one of those animation flip books you made when you were a kid
   <img id="image01" src="blah01.jpg" />
   <img id="image02" src="blah01.jpg" />
   <img id="image03" src="blah01.jpg" />
   // and so on
</div>
//
// now the div that tracks the mouse events this is what I am describing to answer the question
// it could certainly be used above nav items and would have less load time than an image
<div style="position:absolute; left:-1px; top:0px; width:1px; height:200px; border-right: solid 200px transparent; />

In my application for every 2 px the mouse moved left or right I would give the appropriate image visibility while hiding all others and bingo you have an animation. (The empty div worked fine in all non IE browsers, but this worked in IE as well as non IE so no need to write it two ways.)

∞梦里开花 2024-08-27 01:12:31

我能够利用 "Braille Pattern Blank" 这是一个仍然“存在”的不可见的非空白字符,占用一个空间,并允许鼠标​​悬停等事件仍然触发。下面的代码片段显示了这一点(div 的宽度不是零,因为它是空的或仅包含空格):

.notActuallyEmpty {
  background-color: gray;
  width:50px;
}
⠀⠀
<div class="notActuallyEmpty">⠀</div> <!--Unicode Character “⠀” (U+2800)--!>

I was able to make use of the "Braille Pattern Blank" which is an invisible, non-whitespace character that is still "there", takes up a space, and allows events like mouseover to still fire. The snippet below shows this (the div isn't zero width as it would be if it were empty or contained only whitespace):

.notActuallyEmpty {
  background-color: gray;
  width:50px;
}
⠀⠀
<div class="notActuallyEmpty">⠀</div> <!--Unicode Character “⠀” (U+2800)--!>

溺ぐ爱和你が 2024-08-27 01:12:31

如果你不需要支持IE6。在图形程序 (Photoshop) 中创建一个 1x1 的白框图像。将不透明度降低至 1%。另存为 PNG24 或 GIF。然后,将其作为透明 DIV 的背景图像。

这可以解决这个问题并保留任何子元素的不透明度。

If you don't have to support IE6. In your graphics program (Photoshop) create a 1x1 image of a white box. Reduce the opacity to 1%. Save as a PNG24 or GIF. Then, make this the background image for the transparent DIV.

This takes care of the issue and preserves the opacity of any child elements.

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