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.