Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keeping the scroll to bottom

I have a shoutbox and I want to keep the scroll to bottom same as IM windows.

My html is

<div id="shoutContainer">
            <table id="shoutbox">
                <tbody>
                      <!-- shouts here -->
                </tbody>
            </table>
    </div>

My css

#shoutContainer {
    height: 100px; overflow-y: scroll;
}

If its not possible through html and css. Can we achieve this in raw javascript? because I am not using any framework

like image 403
Shishant Avatar asked Apr 16 '10 13:04

Shishant


People also ask

How do I get the scroll at the bottom?

If you want to check whether the user has scrolled to the bottom of the page, you can use the scroll() jQuery event. The given code piece takes the top scroll of the window, so how much the page is scrolled down, it adds the height of the visible window and checks if it is equivalent to the height of the document.

How do you keep the scroll position?

Preserve scroll position allows you to maintain the same scroll location when you transition between two screens. This applies to scroll depth in a vertical scroll, as well as the user's location inside a horizontal scrolling element. Figma automatically preserves your scroll position for Smart Animate.

How do you scroll automatically to the bottom of the page?

To auto scroll a page from top to bottom we can use scrollTop() and height() method in jquery. In this method pass the document's height in scrollTop method to scroll.

How do I keep the bottom scroll on CSS?

use css position top keep it at the bottom {position : relative; bottom:0;} .


1 Answers

Whenever an item is added, do the following:

document.getElementById('shoutContainer').scrollTop = 10000;
// or some other big number

edited

like image 98
James Avatar answered Sep 23 '22 14:09

James