javascript - Scroll Position in HTML document - How to determine - Stack Overflow

Imagine an HTML documetn with a long long list of paragraphs. The user scrolls 52% down the document wi

Imagine an HTML documetn with a long long list of paragraphs. The user scrolls 52% down the document with the scroll bar.

How can I capture that the document is 52% or at paragraph 100 or other metic?

Imagine an HTML documetn with a long long list of paragraphs. The user scrolls 52% down the document with the scroll bar.

How can I capture that the document is 52% or at paragraph 100 or other metic?

Share Improve this question asked Nov 8, 2010 at 4:06 Ian VinkIan Vink 68.9k107 gold badges353 silver badges567 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

Use the two functions below and you can determine what you need.

// getPageScroll() by quirksmode.
// use getPageScroll()[0] for horizontal scrolled amount
// use getPageScroll()[1] for vertical scrolled amount
function getPageScroll() {
    var xScroll, yScroll;
    if (self.pageYOffset) {
      yScroll = self.pageYOffset;
      xScroll = self.pageXOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {
      yScroll = document.documentElement.scrollTop;
      xScroll = document.documentElement.scrollLeft;
    } else if (document.body) {// all other Explorers
      yScroll = document.body.scrollTop;
      xScroll = document.body.scrollLeft;
    }
    return new Array(xScroll,yScroll)
}

// Adapted from getPageSize() by quirksmode.
function getPageHeight() {
    var windowHeight
    if (self.innerHeight) { // all except Explorer
      windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {
      windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
      windowHeight = document.body.clientHeight;
    }
    return windowHeight
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745326273a4622670.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信