与jQuery中的"scrollTop"相反

Zac*_*ght 24 jquery

jQuery有一个名为scrollTop的函数,可用于查找隐藏在当前页面视图上方的像素数.

我不确定为什么,但没有scrollBottom函数返回当前页面视图下方的像素数.

有没有添加此功能的jQuery插件?或者它需要一些精心设计的数学与窗口/文档高度和scrollTop值?

Nic*_*ver 36

你可以为此制作一个非常简单的插件:

$.fn.scrollBottom = function() { 
  return $(document).height() - this.scrollTop() - this.height(); 
};
Run Code Online (Sandbox Code Playgroud)

然后在你想要的任何元素上调用它,例如:

$(window).scrollBottom();  //how many pixels below current view
$("#elem").scrollBottom(); //how many pixels below element
Run Code Online (Sandbox Code Playgroud)

  • 我发现了我的问题:我遇到了这个问题:http://stackoverflow.com/q/12103208/923560.我的HTML文件缺少doctype声明.解决方案是在HTML文件的最顶部添加`<!DOCTYPE html>`. (2认同)