Jquery Animate ScrollTop with easing plugin

时间:2016-10-20 19:06:34

标签: jquery function jquery-animate scrolltop jquery-easing

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 个答案:

答案 0 :(得分:1)

  $(".scroll-top").on("click", function(e){

      e.preventDefault();

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

答案 1 :(得分:0)

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
  });
});