0

I have the following code which scrolls to the bottom of an element (DIV) and it works.

But the animation i snot really smooth... I have seen this done much smoothly.

This is my current code:

var $t = $('#messages');
$t.animate({"scrollTop": $('#messages')[0].scrollHeight}, "slow");

Is there any way to make this smoother using CSS or any other means?

any help would be appreciated.

David Hope
  • 1,256
  • 2
  • 16
  • 44
  • 1
    Possible duplicate of [Smooth scrolling when clicking an anchor link](https://stackoverflow.com/questions/7717527/smooth-scrolling-when-clicking-an-anchor-link) – Obsidian Age Oct 02 '17 at 20:14
  • Try this: https://css-tricks.com/snippets/jquery/smooth-scrolling/ –  Oct 02 '17 at 20:14

1 Answers1

1

You can Use this:

$(function() {
  $('a[href*=#]:not([href=#])').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
      var target = $(this.hash);
      target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
      if (target.length) {
        $('html,body').animate({
          scrollTop: target.offset().top
        }, 1000);
        return false;
      }
    }
  });
});
YakovL
  • 5,213
  • 10
  • 46
  • 71
Kamal
  • 2,320
  • 1
  • 6
  • 12