Javascript HTML文档中的滚动位置-如何确定
想象一个HTML文档包含一长串的段落。用户使用滚动条向下滚动文档52%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
如何获取文档的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
}