實作實需要用到幾個jQuery 函式

scroll()
scrollTop()
height()

DEMO: http://jsbin.com/qenejufoji/edit?html,js,console,output


$(window).scroll(function(){
  // Returns height of browser viewport
  var window_height = $( window ).height();
  
  var window_scrollTop = $(window).scrollTop();
 
  // Returns height of HTML document
  var document_height = $( document ).height();
  
  console.log(window_height);
  console.log(window_scrollTop);
  console.log(document_height);
  
   if(window_height + window_scrollTop == document_height){
     alert('到底部觸發ajax');
   }

});

arrow
arrow

    衛斯理不理 發表在 痞客邦 留言(0) 人氣()