jQuery的滚动击中两次的IE浏览器两次、浏览器、jQuery、IE

2023-09-11 01:15:23 作者:俺要和你古德白~

有这样的code调用一个Ajax每当一个div的滚动击中结束。它的假设是自动动态滚动。此AJAX获取列表的下一个x itens

have this code that calls an ajax whenever the scroll of a div hits the end. It's suppose to be an auto-dynamic scroll. This ajax gets the next X itens of the list.

 $("#gvContacts").scroll(function(){
     var scrolltop=$('#gvContacts').attr('scrollTop');  
     var scrollheight=$('#gvContacts').attr('scrollHeight');  
     var windowheight=$('#gvContacts').attr('clientHeight');                             

     if(scrolltop==(scrollheight-(windowheight)))  
     {                                
        var p = eval($("#pageNumber").val());        
        $("#pageNumber").val(p + 1); // This updates what page should the ajax get next
        loadRelatedFilters(false); //This call an ajax to load more 
     }
 }

它工作正常在FF,Chrome浏览器...它也适用于IE浏览器。但它击中了两次,想不通。每次它击中它得到2页而不是一个。

It works fine on FF, Chrome... it also works on IE. but it hits twice, can't figure out. Everytime it hits the end of the list it gets 2 pages instead of one.

推荐答案

这听起来像你需要的去抖的滚动事件。然而,它的真正的听起来就像是你工作在一个无限滚动 - 我错了

It sounds like you need to debounce the scroll event. However, what it really sounds like is that you're working on an "infinite scroll" - am I wrong?

如果如此 - 只是用什么已经被写入! http://www.infinite-scroll.com/

If so - just use what's already been written! http://www.infinite-scroll.com/