与"scrollTop"相对在jQuery中 [英] Opposite of "scrollTop" in jQuery

查看:95
本文介绍了与"scrollTop"相对在jQuery中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

jQuery has a function called scrollTop which can be used to find the number of pixels hidden above the current page view.

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

I'm not really sure why, but there is no scrollBottom function which returns the number of pixels below the current page view.

是否有添加此功能的jQuery插件?还是需要一些关于窗口/文档高度和scrollTop值的详尽数学运算?

Is there a jQuery plugin which adds this functionality? Or is it going to require some elaborate math with the window/document height and the scrollTop value?

推荐答案

您可以为此创建一个非常简单的插件:

You could make a pretty simple plugin for this:

$.fn.scrollBottom = function() { 
  return $(document).height() - this.scrollTop() - this.height(); 
};

然后在所需的任何元素上调用它,例如:

Then call it on whatever element you wanted, for example:

$(window).scrollBottom();  //how many pixels below current view
$("#elem").scrollBottom(); //how many pixels below element

这篇关于与"scrollTop"相对在jQuery中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆