如何获得向下拖动的滚动条高度? [英] How to get the scroll bar height which is dragged down ?

查看:82
本文介绍了如何获得向下拖动的滚动条高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取被下拉的滚动条高度?

我有一个垂直滚动的页面.我已将滚动条拖动到页面底部.现在,如果我使用"e.screenY",它将仅给出相对于鼠标指针的屏幕高度.如果我尝试使用此"e.screenY"定位"div"(例如,document.getElementById(``divDiscount'').style.top = e.screenY-130 +"px";),它将被定位在页面顶部而不是屏幕顶部.因此,它对用户不可见.我们需要向上滚动才能看到"div".如果我可以获取滚动高度,即它已被拖动了多少高度,则可以找到div.该问题的解决方案是什么?

(注意:如果您有问题,请让我知道:))

How to get the scroll bar height which is dragged down ?

I have a page which is having a vertical scroll. I have dragged the scroll bar till the bottom of the page. Now if I use "e.screenY" it will give only the screen height with respect to mouse pointer. If I try to locate a "div" with this "e.screenY"(like this, document.getElementById(''divDiscount'').style.top = e.screenY - 130 + "px";) it will be located at the top of the page instead of top of the screen. Therefore its not visible to the user. We need to scroll up to see the "div". If I can get scroll height i.e, how much height it has been dragged down, I can locate the div. What would be the solution to this problem?

(Note:If you dint get the question please let me know :) )

推荐答案

您需要将其相对于文档放置,而不是我要说的屏幕.

在这里,您可以使用一些与跨浏览器兼容的javascript来获取文档的高度.

You need to put it relative to the document, not the screen I would say.

Here you have some cross browser compatible javascript to get the document height.

function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}



...或者也许看看这个:

http://www.evolt.org/article/document_body_doctype_switching_and_more/17/30655/ [ ^ ]

祝你好运!



...or maybe have a look at this:

http://www.evolt.org/article/document_body_doctype_switching_and_more/17/30655/[^]

Good luck!


这篇关于如何获得向下拖动的滚动条高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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