开发者

jQuery mousemove performance

When I bind a mousemove event to an element it is working smoothly with every browser except开发者_开发百科 Internet Explorer. With IE the CPU usage is way too much and some associated things (eg. tooltip) are ugly. Is there any way I could rid of the performance problem? (yeah I know, don't use IE :))

UPDATE: Even if I don't do anything in the event handler function, the CPU usage is still high. Here's my code:

$("#container").live("mousemove", function(e){

});

Is it normal?


Are you using jquery selectors in the mousemove event? I have seen cases where the jquery selectors slow down in complex pages, if you put the selector in an event that fires many times, there is noticeable lag. In many cases you can just store the jquery reference to the element before mousemove, then the mousemove uses the element reference instead of again using a selector that internally re-traverses the DOM every time it is called.


You should have no problems binding simple updates to the mouse move event, even in IE. Drag/drop, as seen in a gazillion websites recently, is implemented exactly this way.

If you're seeing massive spikes in CPU, I'd consider perhaps there's a larger underlying cause.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜