鼠标悬停/悬停效果在 IE8 上缓慢
我注意到在 IE8 中,当在包含许多行(本例中为 100 行)的表上使用鼠标悬停事件时,性能会出现奇怪的情况。我尝试了很多不同的方法,但我似乎找不到任何方法来按照我喜欢/需要的速度获得它。
如果我在每个事件上切换类,则所有 IE 版本的性能都会下降,如果我通过 javascript 直接操作 CSS,IE6 和 IE7 会加速很多,但 IE8 的性能仍然很差。
有什么想法吗?我真的很想知道是什么使得鼠标悬停事件与所有其他浏览器相比执行得如此缓慢。
如果这种情况只发生在IE6上我可以理解并让它过去,但是当最新版本的浏览器是最慢的浏览器时,只会有越来越多的用户体验不好。
使用 JQuery 悬停的示例: http://thedungheap.net/research/
编辑:我现在更新了示例,以便很容易看出 10 行和 200 行之间的区别。这是在同一个文档中,所以我猜这不会是整个 DOM 大小的问题
I have noticed a weird performance thing in IE8 when using mouseover events on a table with many rows (100 in this example). I have tried a lot of different approaches but I can't seem to find any way to get it as fast as I like/need.
If I switch classes on each event the performance goes down in all IE versions, and If I use direct manipulation of the CSS through javascript IE6 and IE7 speeds up alot, but IE8 still performs lousy.
Any ideas ? I would really like to know what it is that makes the mouseover event to perform so sluggish compared to all the other browsers.
If this only happened to IE6 I could understand and let it pass, but when the newest version of the browser is the slowest one, there is only going to be more and more users with a bad experience.
Example using JQuery hover: http://thedungheap.net/research/
EDIT: I have now updated the example so that it is easy to see the difference between having 10 rows and 200. This is in the same document, so this cannot be a problem with the whole DOM size, i guess
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
:hover 在 IE8 上非常慢,无论您打算如何实现它。事实上,javascript onmouseover、onmouseout 事件提供了比 CSS 更快的方法来创建悬停效果
IE8 上最快的示例:
较慢的示例:
非常慢的示例: JSFiddle
The :hover IS very slow on IE8, no matter how you intend to implement it. In fact, the javascript onmouseover, onmouseout events provides way faster methods for creating a hover effect, than CSS does
Fastest example on IE8:
Slower example:
VERY slow example: JSFiddle
顺便说一句,对于所有浏览器,您都可以使用 :hover 选择器,仅使用 css。并且仅对于 IE6,您可以添加最快的解决方案。
Btw for all browsers you can use :hover selector using css only. And only for IE6 you can add your fastest soluton.
尝试使用事件冒泡。仅将悬停事件添加到表格中,然后查看目标元素。
Try using event bubbling. Add the hover event to the table only, and then look at the target element.
您是否尝试过看看如果每行只有一个会发生什么?好奇 DOM [或每行] 中的元素数量是否会影响性能。否则,可能是 ie8 在选择器引擎中遍历标签的方式出现问题。这并不是真正的答案,而是值得尝试的事情。
没有IE8,否则我会自己尝试一下。
Have you tried to see what happens if you only have one per row? Curious if it is the number of elements in the DOM [or in each row] could affect performance. Otherwise, it could be an issue with the way ie8 traverses tags in the selector engine. Not really an answer, but something to try.
No IE8 or I'd try it myself.
对我来说似乎足够快,无需实际查看指标。
您可以尝试鼠标悬停/鼠标移出而不是切换。您还可以尝试事件委托,这通常有助于处理 dom 中的众多元素。
Seems fast enough to me, without actually looking at metrics.
You could try mouseover/mouseout instead of toggling. You could also try event delegation, which often helps with this many elements in the dom.
我遇到过这个问题并实施了以下解决方法,
希望这对您有用。
I have faced this issue and implemented the following workaround
I hope this could be useful for you.
很抱歉发布这么旧的答案,但我认为它是相关的,并且该页面在谷歌上排名很高,所以...
哇,我刚刚在这个问题上花了很多时间,我试图使用Javascript,但仍然很慢。
如果您使用背景图像,这是一个解决方案:
这对我来说是一个真正的问题,因为我遇到此问题的项目是我用来对选项卡进行动画处理的左右按钮/箭头上的悬停效果向左和向右,选项卡将位于按钮下方,如果我可以说,选项卡幻灯片放映,当光标进入按钮区域时,正常图像将消失,下面的图像将显示几毫秒,然后,悬停图像将最终显示出来,丑陋。
真正的解决方案是使用图像精灵,这样即使在纯 CSS 中也绝对没有延迟。这个想法是拥有一个包含所有不同图像状态的单个图像(正常/悬停/选定/非活动/等),您将图像设置为背景图像,然后只需调整悬停效果的背景位置值即可其他的。
如果您想更好地了解 css sprites: http://css-tricks.com/css-sprites/
Sorry to post on an answer this old but I think it is relevant and this page is well ranked by google so...
Wow, I just spent a great amount of time on this problem, I tried to use Javascript, but it was still slow.
This is a solution if you use background images :
This was a real issue for me, because the project I had this problem on was the hover effect on Left and Right buttons / arrows that I use to animate tabs left and right, the tabs would go under the buttons, a tab slideshow if I may say and when the cursor entered the button area the normal image would disappear, the image below would be visible for a few millisecs and then, the hover image would eventually display, ugly.
The real solution was to use image sprites, that way there is absolutely no lag even in pure css. The idea is to have a single image with all the differents images states insides (normal / hover / selected / inactive / etc), you set the image as background-image, and you just adjust the background-position value for the hover effect and others.
If you want to know better about css sprites : http://css-tricks.com/css-sprites/