Tutorials Point


  Learn Prototype
  Prototype Resources
  Selected Reading

Copyright © 2014 by tutorialspoint



  Home     References     Discussion Forums     About TP  

Prototype scrollTo() Method


previous next AddThis Social Bookmark Button


Advertisements

This method scrolls the window so that element appears at the top of the viewport.

This has a similar effect than what would be achieved using HTML anchors (except the browser's history is not modified).

Syntax:

element.scrollTo();

Return Value:

  • Returns an HTML element.

Example:

<html>
<head>
<title>Prototype examples</title>

<script type="text/javascript" 
   src="/javascript/prototype.js">
</script>
<script>

function showResult()
{

   $('heading').scrollTo();
     
}

</script>
</head>

<body">
  <h1 id="heading">This is the heading.</h1>
  <p id="test">Click the button see the result.</p>
  <p id="test">Click the button see the result.</p>
  <p id="test">Click the button see the result.</p>
  <p id="test">Click the button see the result.</p>
  <p id="test">Click the button see the result.</p>
  <p id="test">Click the button see the result.</p>
  <p id="test">Click the button see the result.</p>
  <p id="test">Click the button see the result.</p>
  <p id="test">Click the button see the result.</p>
  <p id="test">Click the button see the result.</p>
  <p id="test">Click the button see the result.</p>
  <p id="test">Click the button see the result.</p>
  <p id="test">Click the button see the result.</p>
  <p id="test">Click the button see the result.</p>
  <p id="test">Click the button see the result.</p>
  <p id="test">Click the button see the result.</p>
  <p id="test">Click the button see the result.</p>
  <p id="test">Click the button see the result.</p>
  <p id="test">Click the button see the result.</p>
  <p id="test">Click the button see the result.</p>
  <p id="test">Click the button see the result.</p>
  <p id="test">Click the button see the result.</p>
  <p id="test">Click the button see the result.</p>
  <p id="test">Click the button see the result.</p>
  
  <input type="button" value="Click" onclick="showResult();"/>

</body>
</html>

To understand it in better way you can Try it yourself.



previous next Printer Friendly

Advertisements


  

Advertisements