Javascript automatically scrolls the DIV to the bottom-4 Methods

Source: Internet
Author: User
This article introduces the javascript code generator to allow the DIV's scroll bar to automatically scroll to the bottom. It mainly uses the scrollTop attribute to control the position of the scroll bar. For more information about the code generator, see. To create an online chat program, you need to scroll the obtained information in real time during the final modification to ensure that the user can always see the latest message.

The chat program is designed based on AJAX and does not use a framework. The message container is a DIV, so the question is how to control the scroll bar of the DIV.

You can set the scrollTop attribute to control the position of a scroll bar. For details, see:
Http://hi.baidu.com/chen1345789/blog/item/de727bfb45587b176d22eba1.html

UmentElement. scrollTop, instead of document. body. scrollTop, describes the scroll bar of the entire page for half a day. I cannot use this method. Because it is not a framework structure, it is impossible to use the body's scroll bar to control browsing information.

There is very little information on this issue on the Internet, and CSDN also says there is no way.

I don't have to worry about it. Later I checked the DHTML manual and learned that DIV has a doScroll method that can be used to simulate scroll bar clicking. But it is disappointing that it is completely invalid when it comes to me. Isn't it not supported by XHTML?

Finally, I found three ways to control DIV content scrolling:
Method 1:
Use the anchor tag to scroll to the position, and then use the click method to simulate clicking to scroll to the anchor location.

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.