jQuery load content when scroll to bottom-100px of page, multiple events fired

后端 未结 3 2067
时光说笑
时光说笑 2020-12-02 18:00

I want an event to load more content when a user is scrolling and reaches nearly the bottom of the page, say about 100px from the bottom, the problem is that the events get

3条回答
  •  孤街浪徒
    2020-12-02 18:36

    I was having this same problem too. I came across this link and it really helped (and worked)!

    Update: I looked at the code and I think that when you rebind, you are missing the function to rebind to.

    jsFiddle

     function loadMore()
    {
       console.log("More loaded");
        $("body").append("
    "); $(window).bind('scroll', bindScroll); } function bindScroll(){ if($(window).scrollTop() + $(window).height() > $(document).height() - 100) { $(window).unbind('scroll'); loadMore(); } } $(window).scroll(bindScroll);

提交回复
热议问题