Three methods to implement Javascript control of ScrollBar (scroll bar)

Source: Internet
Author: User

This article focuses on ScrollBar control. Three methods are provided to control ScrollBar with Javascript ), I hope you will have a deep understanding of how to control the scroll bar through this article.

Use Javascript to control ScrollBar (scroll bar)

The following items are automatically rolled to the bottom by default. to scroll to the top, you only need to change document. body. scrollHeight to 0.

Method 1: Use scroll

 
 
  1. <body onload="scroll(0,document.body.scrollHeight) ">   
  2. <script>   
  3. document.write(new Array(100).join("<br>"))   
  4. </script>   

Method 2: Use the scrollBy Method

 
 
  1. <body onload="scrollBy(0,document.body.scrollHeight) ">   
  2. <script>   
  3. document.write(new Array(100).join("<br>"))   
  4. </script>   
  5.  

Method 3: Use the scrollTo Method

 
 
  1. <body onload="scrollTo(0,document.body.scrollHeight)">   
  2. <script>   
  3. document.write(new Array(100).join("<br>"))   
  4. </script>   
  5.  

If you want to control the ScrollBar of the Framework in the framework, add parent, for example, parent. scrollTo );
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.