0

I want to get scroll bar at bottom of div as soon as page loads but it is not working

My design:

<div class="panel-body" id="dvMsgBody" style="padding: 0px;">
    <div id="dvMessage" class="col-lg-12" style="height: 500px; overflow: auto; margin: 0px; padding: 0px; width: 100%;">
    </div>
</div>

My jQuery:

//not working
{
    $("#divChatWindow").find('#dvMsgBody').find('#dvMessage').scrollTop($('#dvMessage')[0].scrollHeight);
}


//not working
{
    $("#divChatWindow").find('#dvMsgBody').find('#dvMessage').animate({ scrollTop: $('#dvMessage')[0].scrollHeight }, 1000);
}

//not working
{
    $('#dvMessage').scrollTop($('#dvMessage')[0].scrollHeight);
}
rtruszk
  • 3,902
  • 13
  • 36
  • 53
Chetan
  • 13
  • 6
  • What do you mean you want a scroll bar at the bottom of the div? Could you provide a [jsfiddle](http://www.jsfiddle.net) of what you're current implementation looks like – asdf Sep 08 '15 at 07:18
  • when do you call those functions? what is the event? – Alex Sep 08 '15 at 07:38
  • 1
    Tip: IDs should be unique, therefore a single selector like `$('#dvMessage')` would suffice. – emerson.marini Sep 08 '15 at 07:41

2 Answers2

0

Working fiddle

(function($) {
  $(window).load(function() {
    $('#dvMessage').stop().animate({ scrollTop: $('#dvMessage').prop('scrollHeight') }, 1000);
  });
})(jQuery);
Alex
  • 9,911
  • 5
  • 33
  • 52
0

I have create a simply jsFiddle for you : https://jsfiddle.net/azp9vjyk/

jQuery

$(function()
  {
    $('.scroll').animate({ scrollTop: $('.scroll').prop('scrollHeight') }, 5000);
});

Html

<div class="scroll">Lorem ipsum. Lorem ipsum. Lorem ipsum. Lorem ipsum. Lorem ipsum. Lorem ipsum. Lorem ipsum. Lorem ipsum. Lorem ipsum. Lorem ipsum. </div>
Canvas
  • 5,779
  • 9
  • 55
  • 98