Alert using Jquery when Scroll to end of Page

后端 未结 6 1753
余生分开走
余生分开走 2020-12-31 15:43

Is there a way to find out page end using Jquery, so that a simple message can be displayed saying you have reached end of the page.

6条回答
  •  情话喂你
    2020-12-31 15:47

    To avoid duplicate console.log('end of page'), you need create a setTimeout, like this:

    var doc = $(document), w = $(window), timer;
    
    doc.on('scroll', function(){
    
        if(doc.scrollTop() + w.height() >= doc.height()){
    
            if(typeof timer !== 'undefined') clearTimeout(timer);
    
            timer = setTimeout(function(){
                console.log('end of page');
            }, 50);
    
        }
    
    });
    

提交回复
热议问题