15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

172<br />

<strong>JavaScript</strong> <strong>Examples</strong> <strong>Bible</strong>: The Essential Companion to <strong>JavaScript</strong> <strong>Bible</strong><br />

windowObject.scrollBy()<br />

Example<br />

To work with the scrollTo() method, you can use Listings 16-31 through 16-33<br />

(the window.scroll() method) but substitute window.scrollTo() for window.<br />

scroll(). The results should be the same. For scrollBy(), the example starts with<br />

the frameset in Listing 16-34. It loads the same content document as the window.<br />

scroll() example (Listing 16-32), but the control panel (Listing 16-35) provides<br />

input to experiment with the scrollBy() method.<br />

Listing 16-34: Frameset for ScrollBy Controller<br />

<br />

<br />

window.scrollBy() Method<br />

<br />

<br />

<br />

<br />

<br />

<br />

Notice in Listing 16-35 that all references to window properties and methods are<br />

directed to the display frame. String values retrieved from text fields are converted<br />

to number with the parseInt() global function.<br />

Listing 16-35: ScrollBy Controller<br />

<br />

<br />

ScrollBy Controller<br />

<br />

function page(direction) {<br />

var pixFrame = parent.display<br />

var deltaY = (pixFrame.innerHeight) ? pixFrame.innerHeight :<br />

pixFrame.document.body.scrollHeight<br />

if (direction == “up”) {<br />

deltaY = -deltaY<br />

}<br />

parent.display.scrollBy(0, deltaY)<br />

}<br />

function customScroll(form) {<br />

parent.display.scrollBy(parseInt(form.x.value), parseInt(form.y.value))<br />

}<br />

<br />

<br />

<br />

ScrollBy Controller<br />

<br />

Enter an Horizontal increment

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!