jquery implements scroll bar always at the bottom

Source: Internet
Author: User

I believe that we sometimes show some real-time data display and the amount of data is very large, because it is not possible to see the most effective data on the same page, so we need to put the scroll bar to the bottom, so that we see the most needed data and information; Here's an obvious example, take the ping for Windows, When we are long ping, this time the data will be more and more, and still accumulate, the new data is all in the back, so the scroll bar has been at the bottom of a lot!

Guys can look at the Windows cmd in the ping address-T, this time will always ping, at first, the data may be smaller, the same screen can be seen

But the time is long, the data is more and more, the same screen can not see at all, and the most effective data are at the bottom, so this time we should see the bottom of the most want to see the data


As long as we put the scroll bar at the bottom, we can achieve the effect!!! OK, not much to say, first show you a small instance, is a textarea and div to do the demo:

<textarea id= "TestScroll1" style= "width:300px; height:200px;border:1px #ccc Solid; Resize:none; " ></textarea><div id= "TestScroll2" style= "width:300px; height:200px;border:1px #ccc Solid; Overflow-y: Scroll;float:left; " ></div><input type= "button" value= "Start" onclick= "Start ();" ><input type= "button" value= "Stop" onclick= "Stop ();" >

This is the simulated HTML element that we need, and the next is the key:

var count = 1000;function Start () {$ ("#testScroll1"). HTML ("); $ (" #testScroll2 "). HTML ("); Timebox = SetInterval ( Function () {$ ("#testScroll1"). Append (' number:[' +count+ ')--->i love you\n ') var scrolltop = $ ("#testScroll1") [0]. scrollheight;$ ("#testScroll1"). ScrollTop (scrolltop); $ ("#testScroll2"). Append (' number:[' +count+ ']--->i love You<br/> ') $ ("#testScroll2"). ScrollTop ($ ("#testScroll2") [0].scrollheight); count--;if (count = = 0) { Clearinterval (timebox); count = 1000;}},1000);} function Stop () {count = 1000;clearinterval (Timebox);}

The details of the demo is not handled, but also please forgive me, you understand the meaning of the line, summed up is a sentence:

$ ("#dom_id"). ScrollTop ($ ("#dom_id") [0].scrollheight];

Here to remind you, if the effect does not come out, please note that the element is super-find the right!

Show the effect to the folks to see:

It's the effect we want! Thank you for your attention!

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.