[英]How to get the amount of pixels scrolled down the page with jQuery?
現在我知道我可以使用scrollTop()
,但這讓我獲得了屏幕頂部的像素數量。 是否有可能從屏幕底部到頂部獲得px
的數量?
只需為具有類似於 scrollTop(但相反)的屬性的函數分配一個變量,如下所示:
$.fn.scrollBottom = function() {
return $(document).height() - this.scrollTop() - this.height();
};
然后只需按如下方式調用它:
$(window).scrollBottom(); //how many pixels below current view
$("#elem").scrollBottom(); //how many pixels below element
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.