小编Bil*_*lyJ的帖子

JQuery:我的'滚动'事件很慢.我究竟做错了什么?

我有4 DIV,scroll当你滚动其中一个div时我想要一个事件被触发.这是下面的代码.

$('#div1, #div2, #div3, #div4').scroll(function() {
    alert('...');
});
Run Code Online (Sandbox Code Playgroud)

在Firefox/Chrome中,运行速度很快; 但是,在Internet Explorer中,它运行速度很慢,实际上阻止了我滚动div.

我正在使用最新版本的JQuery(v.1.4.1).

问题:运行上面的代码有更有效的方法吗?如果是这样,怎么样?

更新:自从被问及,我已经在我的整个代码下面包含:

$('#div1, #div2, #div3, #div4').scroll(function() {
   /* find the closest (hlisting) home listing to the middle of the scrollwindow */ 
    var scrollElemPos = activeHomeDiv.offset();
    var newHighlightDiv = $(document.elementFromPoint(
        scrollElemPos.left + activeHomeDiv.width()  / 2,
        scrollElemPos.top  + activeHomeDiv.height() / 2)
    ).closest('.hlisting');
    if(newHighlightDiv.is(".HighlightRow")) return;
    $('.HighlightRow').removeClass("HighlightRow");
    newHighlightDiv.addClass('HighlightRow');

   /* change the map marker icon to denote the currently focused on home */
   var activeHomeID = newHighlightDiv.attr("id"); …
Run Code Online (Sandbox Code Playgroud)

javascript jquery micro-optimization

3
推荐指数
1
解决办法
7520
查看次数

标签 统计

javascript ×1

jquery ×1

micro-optimization ×1