john
john

Reputation: 29

My script works only when when there is an alert function in the script

My script works only when i have an alert function in it.

Well I want to scroll my div to bottom . I researched but yet, my script does not execute without an alert function

$(document).ready(function() {

  $("#display-message").animate({ scrollTop: $('#display-message').prop("scrollHeight")}, 1);

});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="chat-log">
  <div id="display-message">
  </div>
</div>

Upvotes: 0

Views: 69

Answers (1)

Kuldeep Sharma
Kuldeep Sharma

Reputation: 39

Actually you need to animate body like this:

$(document).ready(function() {
  $('html, body').animate({
    scrollTop: $("#display-message").offset().top
  }, 2000);
});

Upvotes: 1

Related Questions