在IE中加速多个onmouseover事件 [英] speeding up multiple onmouseover events in IE

查看:171
本文介绍了在IE中加速多个onmouseover事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页,上面有很多(最多100个)html元素。每个人都有一个onmouseover事件,根据哪一个元素被盘旋而被注册以触发逻辑和渲染。



我发现在IE中,更多的onmouseover事件注册时间越长,他们开火。在Firefox中,速度很好,在Chrome中速度更快!

有谁知道这个问题的解决方案。我想也许注册一个onmousemove事件,并试图从协调中检索DOM元素,但我不确定如何做到这一点,或者它只是一个解决问题的方法。

解决方案

附加一个onmouseover或mousemove(我认为这两个泡沫,不记得)事件的身体,当你悬停在你的实际元素,你可以处理你需要这样做,因为它会冒泡到身体,在那里你可以处理你实际上被挖出的元素。您可以使用该元素的自定义属性或expando属性来处理在特定元素的鼠标悬停中需要执行的操作。



您应该只将事件附加为当你不再需要它们时,你需要它们并将它们分开。在微不足道的页面上,这可能不是必需的,但在像您这样的场景中,它可以提高客户端性能。我们曾经在这样的地方做过这样的工作,当我们在页面上有成千上万的表单元素时。



我的两美分,
nickyt


I have a web page with many (up to 100+) html elements on it. Each one has an onmouseover event registered to fire to do some logic and rendering depending on which element is hovered over.

I am finding that in IE the more onmouseover events that are regitered the longer they take to fire. In Firefox the speed is fine and in Chrome even faster!

Does anyone know a solution to this problem. I thought perhaps registering a single onmousemove event and trying to retrieve the DOM element from the co-ordinates but I'm unsure how to do this or if its just a fudge around the problem.

解决方案

Attach an onmouseover or mousemove (I think both of these bubble, can't remember) event to the body and when you hover over your actual elements, you can handle what you need to do as it will bubble up to the body where you can handle the element you actually moused over. You can use custom attributes or expando properties of that element to handle what ever you need to do in the mouseover for the specific element.

You should really only be attaching events as you need them and detaching them when you no longer need them. On trivial pages this is probably not required, but in a scenario like yours, it will improve client-side performance. We used to do stuff like this where I worked when we would have thousands of form elements on a page.

My two cents, nickyt

这篇关于在IE中加速多个onmouseover事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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