Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/462.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript HTML文档中的滚动位置-如何确定_Javascript_Html - Fatal编程技术网

Javascript HTML文档中的滚动位置-如何确定

Javascript HTML文档中的滚动位置-如何确定,javascript,html,Javascript,Html,想象一个HTML文档包含一长串的段落。用户使用滚动条向下滚动文档52% 如何获取文档的52%或第100段或其他MEDIC?使用以下两个功能,您可以确定您需要什么 // getPageScroll() by quirksmode.com // use getPageScroll()[0] for horizontal scrolled amount // use getPageScroll()[1] for vertical scrolled amount function getPageScro

想象一个HTML文档包含一长串的段落。用户使用滚动条向下滚动文档52%


如何获取文档的52%或第100段或其他MEDIC?使用以下两个功能,您可以确定您需要什么

// getPageScroll() by quirksmode.com
// 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.com
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
}