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.

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

Example<br />

Use The Evaluator (Chapter 13 in the <strong>JavaScript</strong> <strong>Bible</strong>) to experiment with the<br />

scrollIntoView() method. Resize the browser window height so that you can see<br />

only the topmost text box and the Results textarea. Enter each of the following<br />

statements into the top text box and see where the myP element comes into view:<br />

myP.scrollIntoView()<br />

myP.scrollIntoView(false)<br />

Expand the height of the browser window until you can see part of the table<br />

lower on the page. If you enter<br />

myTable.scrollIntoView(false)<br />

into the top text box, the page scrolls to bring the bottom of the table to the bottom<br />

of the window. But if you use the default parameter (true or empty),<br />

myTable.scrollIntoView()<br />

the page scrolls as far as it can in an effort to align the top of the element as closely<br />

as possible to the top of the window. The page cannot scroll beyond its normal<br />

scrolling maximum (although if the element is a positioned element, you can use<br />

dynamic positioning to place it wherever you want — including “off the page”).<br />

Also, if you shrink the window and try to scroll the top of the table to the top of the<br />

window, be aware that the TABLE element contains a CAPTION element so the caption<br />

is flush with the top of the window.<br />

setActive()<br />

elementObject.setActive()<br />

NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5<br />

Compatibility ✓<br />

Example<br />

Use The Evaluator (Chapter 13 in the <strong>JavaScript</strong> <strong>Bible</strong>) to compare the<br />

setActive() and focus() methods. With the page scrolled to the top and the window<br />

sized so that you cannot see the sample check box near the bottom of the<br />

page, enter the following statement into the top text box:<br />

document.forms[1].myCheckbox.setActive()<br />

Scroll down to see that the checkbox has operational focus (press the spacebar<br />

to see). Now, scroll back to the top and enter the following:<br />

document.forms[1].myCheckbox.focus()<br />

This time, the checkbox gets focus and the page automatically scrolls the object<br />

into view.

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

Saved successfully!

Ooh no, something went wrong!