Behseini
Behseini

Reputation: 6330

Pushing Vertical Scrollbar to Bottom Of div as Item added

Can you please take a look at THIS DEMO and following code and let me know how I can keep the vertical Scrollbar at the bottom (displaying latest added content- items)

<div>
    <ul>
        <li>Item</li>
        <li>Item</li>
        <li>Item</li>
    </ul>
</div>
<button id="append">Add Item</button>

$(document).ready(function () {
    $("#append").click(function () {
        $('ul').append('<li>New Item</li>');
        $('div').animate({
            scrollDown: $('div').attr(20)
        });
    });
});

Upvotes: 0

Views: 811

Answers (1)

DaniP
DaniP

Reputation: 38252

You can use this:

$('div').animate({
    scrollTop: $('div')[0].scrollHeight}, 1000
);

The demo http://jsfiddle.net/5cuGg/7/

Upvotes: 2

Related Questions