scroll事件適用于window對象,但也可滾動iframe框架與CSS overflow屬性設置為scroll的元素。
注意:(window).height()和(document).height()的區別
jQuery(window).height()代表了當前可見區域的大小,而jQuery(document).height()則代表了整個文檔的高度,可視具體情況使用.
注意當瀏覽器窗口大小改變時(如最大化或拉大窗口后) jQuery(window).height() 隨之改變,但是jQuery(document).height()是不變的。
$(document).scrollTop() 獲取垂直滾動的距離 即當前滾動的地方的窗口頂端到整個頁面頂端的距離
$(document).scrollLeft() 這是獲取水平滾動條的距離
要獲取頂端 只需要獲取到scrollTop()==0的時候 就是頂端了
要獲取底端 只要獲取scrollTop()>=$(document).height()-$(window).height() 就可以知道已經滾動到底端了
新聞熱點
疑難解答