Forum Moderators: open
var iframe = document.getElementsByTagName("iframe")[0];
iframe.scrollByPages(1);
My issue is the last page: scollByPage(1) on a short last page looks goofy (because the last page gets scrolled only a little and still shows for the duration of the scroll. I think I would like to pad (body.style.paddingBottom) the body of the document contained in the iframe with the difference of the last page:
iframeheight - (divheight % iframeheight)
My question at this point is, is this the best way to go? How does scrollByPages calculate what it constitutes a page's worth of data? scrollByPages flips down a page's worth with just the last couple lines of the previous page shown nicely at the top of the next for continuity.
thanks!
var iframe = document.getElementsByTagName("iframe")[0];
iframe.scrollByPages(1); Are you trying to scroll an IFRAME from outside of that IFRAME, or from the document inside?! I assume from inside, as I tried to do this a short while back (from outside) and couldn't - since scrollByPages and scrollTo are not supported on an iframe element?! Am I missing something - is there a way?
Sorry, I can't offer any real help on your specific question, but I would have thought that maybe just adding a series of '<br>'s may be sufficient to establish the end of the page, but otherwise your method sounds pretty good..... alternatively (no iframe) use a div (fixed width, height, containing your page) within another div (overflow:hidden) then you can scroll the inner div (up, down, left, right) with pixel precision? Just a thought.
Also, to follow up on my earlier post, what works for me is indeed to pad the content to be scrolled with the appropriate height. In my example, I am inserting an empty div of the padding height.
I caclulate the padding like this:
var mod = dataheight % scrollerheight;
var diff = scrollerheight - mod;
Here's a whole snippet, assuming "scroller" is the iframe containing the data:
var scroller = document.getElementById("scroller");
var odiv = scroller.contentDocument.getElementById("scrollbody");
if (odiv) {
if (window.scroller.scrollMaxY > 0) {
var scrollerheight = parseInt(document.getElementsByTagName("iframe")[0].offsetHeight);
var dataheight = odiv.offsetHeight;
var mod = dataheight % scrollerheight;
var diff = scrollerheight - mod;
if (mod > 0) {
//odiv.style.paddingBottom = diff + "px";
odiv.innerHTML += "<div style=\"background-color: transparent; width: 100%; height:"+diff+"px; \"></div>";
}
}
}
// attach handler to reset the scroll back to top when bottom is reached
// This, in conjunction with bottom-padding the document, prevents an undesirable "partial scroll"
// on the last page, which is typically less than a "scroll page worth" of data.
var iframe = window.scroller;
iframe.onscroll = function() {
if (iframe.scrollY >= iframe.scrollMaxY) {
iframe.scrollTo(0, 0);
}
};
function scroller_scroll() {
var scroller = window.scroller;
if (scroller) {
// scroll document only if the doc is not scrolled to the top (and intrinsically if the doc is long enough to be scrolled)
if (scroller.scrollY < scroller.scrollMaxY) {
var heightmod = parseInt(scroller.document.body.offsetHeight) % parseInt(scroller.scrollMaxY);;
var iframeheight = parseInt(document.getElementsByTagName("iframe")[0].offsetHeight);
scroller.scrollByPages(1);
} else {
// scroll the doc back to the top
scroller.scrollTo(0, 0);
}
}
setTimeout("scroller_scroll();", SCROLLPAUSEDURATION);
}
<iframe name="scroller" id="scroller" src="iframe-src.php" style="width: 100%; border: 0px;">
</iframe>