Detect when Scroll reaches the BOTTOM of the page [ without jQuery ]

前端 未结 5 812
终归单人心
终归单人心 2020-12-14 03:20

I want to alert something when the scroll reaches the BOTTOM of the page, like this:

$(function(){
  $(document).scroll(function() {
    if($(document).scrol         


        
5条回答
  •  爱一瞬间的悲伤
    2020-12-14 03:30

    if(window.addEventListener){
        window.addEventListener('scroll',scroll)
    }else if(window.attachEvent){
        window.attachEvent('onscroll',scroll);
    }
    
    function scroll(ev){
        var st = Math.max(document.documentElement.scrollTop,document.body.scrollTop);
        if(!st){
                console.log('top');
        }else if((st+document.documentElement.clientHeight)>=document.documentElement.scrollHeight ){
               console.log('bottom');
        }
    }
    

    example: http://jsfiddle.net/ampersand/AEnzJ/

    tested with http://browserling.com in chrome 17/18, safari 5, ff 10/11.0, ie 7-9

提交回复
热议问题