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 badges1 Answer
Reset to default 6Use 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条)