Scrolling a Window


You can use the scroll , scrollBy , and scrollTo methods to scroll a window's content. Here's how you use these methods :

 window.scroll(  iX  ,  iY  )  window.scrollBy(  iX  ,  iY  )  window.scrollTo(  iX  ,  iY  ) 

Here are the arguments of these methods:

  • iX . Integer that specifies the horizontal scroll offset ( scrollBy ) or new position ( scroll and scrollTo ), in pixels. Positive values scroll the window right, and negative values scroll it left.

  • iY . Integer that specifies the vertical scroll offset ( scrollBy ) or new position ( scroll and scrollTo ), in pixels. Positive values scroll the window down, and negative values scroll it up.

Here's an example that uses the scroll method to scroll a window when the user clicks a button:

(Listing 08-08.html on the web site)
 <HTML>      <HEAD>          <TITLE>              Scrolling Windows          </TITLE>          <SCRIPT LANGUAGE="JavaScript">              <!--  function scroller()   {   window.scroll(0, 100)   }  // -->          </SCRIPT>      </HEAD>      <BODY>          <H1>Scrolling Windows</H1>          <FORM>              <INPUT TYPE="BUTTON" ONCLICK="scroller()" VALUE="Click Me!">          </FORM>          <BR>          <BR>          <BR>          <BR>          <BR>          <BR>          <BR>          <BR>          <BR>          <BR>          <BR>          <BR>          <BR>          <BR>          <BR>          <BR>          <BR>      </BODY>  </HTML> 

Actually, the scroll method has been more or less replaced by the scrollTo method these dayswhich does the same thingalthough the scroll method is still available. The Netscape Navigator also supports two handy methods scrollByLines and scrollByPages that enable you to scroll by a given number of lines and pages.



Inside Javascript
Inside JavaScript
ISBN: 0735712859
EAN: 2147483647
Year: 2005
Pages: 492
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net