[an error occurred while processing this directive]

JavaScript scrollBy() method


JavaScript method scrollBy() can be used to scroll window by the provided number of pixels. One most important thing here to notice is that it can scroll windows only if the scrolling property is visible. If scrolling property would not be visible it would not be applied.

Syntax :

 window.scrollBy( xAxis, yAxis) ;

where xAxis specifies the number of pixels window is to be scrolled along X-axis and yAxis specifies the number of pixels window is to be scrolled along Y-axis and both of these arguments are required.

Description of code:

To illustrate the use of scrollBy() method, we have created a simple example which will scroll window by the 100, 100 pixels position on the X-axis and Y-axis both. Here in HTML page we have created a button "Scroll" which calls the function scrollWindow() when clicked. In this function we have called the scrollBy() method with the window object.

 function scrollWindow()

Here is the full HTML code for scrollBymethod.html as follows :

  <script language="JavaScript">
  function scrollWindow()
 <div style="background: #ff9900; width:'100%';"
  <font color="#0000ff" size="12pt">
	<b>scrollby Example</b>
 <input type="button" onclick="scrollWindow()" 
          value="Scroll" />

Output :

Click on the "Scroll" button to scroll window upward with the 100 pixels on X-axis and 100 pixels on Y-axis.

You can see that it has scrolled the window with the X-axis and Y-axis positions provided into scrollBy() method.

You can also download the full source code by the following link.

Download Source Code


[an error occurred while processing this directive]