Jquery Animate ScrollTop with easing plugin

1.1k views Asked by At

I have this jquery code to scroll to an element when another is clicked

$("#element1").click(function() {
        $('html, body').animate({ scrollTop: $("#element2").offset().top }, 1000);
});

Now i need to implement an easeInOutCirc easing on this movement, using the Jquery Easing Plugin http://gsgd.co.uk/sandbox/jquery/easing/

Never seem to get it right, please help

2

There are 2 answers

1
w3sic3 On

Like it said in the documentation, you have to do :

$("#element1").click(function(e) {
  $('html, body').animate({
    scrollTop: $("#element2").offset().top
  },
  {
    duration: 1000,
    easing: easeInOutCirc
  });
});
0
Rubel Hossain On
  $(".scroll-top").on("click", function(e){

      e.preventDefault();

       $("html, body").animate({scrollTop:"0"},900,"easeInSine");
  });