简体   繁体   English

将鼠标悬停在div上时无法在IE中悬停

[英]Hover in IE not working when hovering over full div

I am using jquery addClass code to show/hide elements when rolling over a div. 我在滚动div时使用jquery addClass代码显示/隐藏元素。 in all browsers it works but in IE it only works when i rollover some text, not the full div. 在所有浏览器中都可以,但是在IE中,只有当我滚动显示某些文本而不是整个div时,它才能工作。

so in this example, if I rollover the showingtext section of the main div, the hiddentext div will show. 因此,在此示例中,如果将鼠标移到主div的showingtext部分,则将显示hiddentext div。 but if I mouse into the space in between the two floating divs (where there is now text or anything), the hover doesnt work. 但是,如果我将鼠标悬停在两个浮动div之间的空间(现在有文本或其他内容)中,则悬停将不起作用。

UPDATE: the code below seems to work, but my production code does not. 更新:下面的代码似乎有效,但是我的生产代码无效。 Please refer to this link: jsfiddle.net/H2anm/5 There are some broken images and such, but if you roll your mouse over the element into the whitespace to the right of the usernames, the location coordinates and the Pref.brand: Gamehouse.. or some of the surrounding whitespace of the Share/Bookmark links, the div collapses and the buttons/bgcolor change disappear. 请参考此链接: jsfiddle.net/H2anm/5有一些损坏的图像等,但是如果将鼠标悬停在该元素上,进入用户名,位置坐标和Pref.brand右侧的空白处:Gamehouse ..或“共享/书签”链接的某些周围空白,div折叠并且按钮/ bgcolor更改消失。

javascript: javascript:

$(function() {
$("div.DivThatsTriggeredOnRollover").hover( 
function() {  $("div.hiddentext").addClass("hiddentextShow"); },
function() { $("div.hiddentext").removeClass("hiddentextShow"); });
});

pseudo-html code: 伪html代码:

<div class="DivThatsTriggeredOnRollover" style="width:500px;">

<div id="showingtext" style="float:left;width:100px;">
here is showing text
</div>

<div class="hiddentext" style="float:right;width:100px;">
here is hidden text
</div>

</div>

Actually, everything works as expected (tested in IE6-7-8): 实际上,一切都按预期工作(在IE6-7-8中进行了测试):

http://jsfiddle.net/ZDyyU/ http://jsfiddle.net/ZDyyU/

If you mouse over anything inside the .DivThatsTriggeredOnRollover , the .hiddentext will show and hide when you mouse out. 如果将鼠标悬停在.DivThatsTriggeredOnRollover内部的任何内容上, .DivThatsTriggeredOnRollover鼠标.hiddentext将显示和隐藏.hiddentext .showingtext plays no part in this whatsoever, it's just there. .showingtext不会在其中.showingtext ,它就在那里。

turns out that in IE7 if you have multiple floats inside of a larger div and you specify a width in one of the inner floating divs, you have to specify a width in the outermost ones as well. 事实证明,在IE7中,如果在一个较大的div内有多个浮点,并且在内部浮点div之一中指定了宽度,则还必须在最外面的 div 中指定一个宽度 im not sure why this is the case, but it has been fixed in the version of my code here: http://jsfiddle.net/H2anm/8/ 我不确定为什么会这样,但是在我的代码版本中,此问题已得到修复: http : //jsfiddle.net/H2anm/8/

I needed to specify a width for the entire outer div, since I had specified one for the gray div. 我需要为整个外部div指定宽度,因为我为灰色div指定了宽度。 prior to that, if I rolled off of the red/gray the hover flip didnt work. 在此之前,如果我滚开红色/灰色,则悬停翻转无效。

your code seemed to be perfect. 您的代码似乎是完美的。 don't know what is going wrong 不知道出了什么问题

http://jsbin.com/udaqi4 http://jsbin.com/udaqi4

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

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