是否有可能在jquery中找到从底部到当前滚动状态的距离

12 javascript

假设已向下滚动到网页的中间位置.

是否有可能从底部找到距离,长度或像素?

就像当滚动条击中底部然后它的0但是如果它从底部500px然后我需要500px值.

Cro*_*zin 14

它不是那么精确但有效:

var scrollPosition = window.pageYOffset;
var windowSize     = window.innerHeight;
var bodyHeight     = document.body.offsetHeight;

alert(Math.max(bodyHeight - (scrollPosition + windowSize), 0));
Run Code Online (Sandbox Code Playgroud)

  • 这回答了你的问题 - 你没有提到ID的图像.请重新说出您的问题. (16认同)

小智 5

也试试这个:

$(document).height() - ($('body').height() + $('body').scrollTop())
Run Code Online (Sandbox Code Playgroud)