Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery slimScroll to always start at the bottom

I have a container that have already a slimscroll, and a button to add new item to the last element. I want the scrollBar of slimscroll to always start at the bottom. Any help please? :(

<div>
  <ul id="item-container">
    <li>item 1</li>
    <li>item 2</li>
    <li>item 3</li>
    <li>item 4</li>
    <li>item 5</li>
  </ul>
</div>

<input type="text" placeholder="add another item" id="add-input"/>
<button id="add-btn">Add</button>

Need help badly :(

http://jsfiddle.net/qh8ye/1/

like image 503
meetmahpuppy Avatar asked Apr 15 '14 16:04

meetmahpuppy


2 Answers

I solved the problem, it seems I just have to add this code in the bottom every time I add the new item. Cheers! thanks! @gulty

var scrollTo_int = itemContainer.prop('scrollHeight') + 'px';
    itemContainer.slimScroll({
    scrollTo : scrollTo_int,
    height: '200px',
    start: 'bottom',
    alwaysVisible: true
});

http://jsfiddle.net/qh8ye/3/

like image 102
meetmahpuppy Avatar answered Sep 29 '22 10:09

meetmahpuppy


This was enough for me:

$('#messagelist').slimScroll({
        start: 'bottom'
});

Thanks meetmahpuppy!

like image 25
Admir Heric Avatar answered Sep 29 '22 11:09

Admir Heric