Search code examples
jqueryanimationpluginsscrolleasing

Use jQuery easing plugin with a scrolling function


I looked for this but i found how to use it with ScrollTo. This one is different.

I need to get the jQuery Easing Plugin working with this function:

function ira(id){
      $('html,body').animate({scrollTop: $("#"+id).offset().top}, 700);
}

There's not much more to explain... Thanks in advance for the help!

...

Also, I would like to know if it's possible to set a speed instead of a duration for the animation, so that it takes less if I'm close from my target or more if I'm far from it.

Thanks again!


Solution

  • jQuery animations only accepts a duration to determine the speed. For the easing, include the easing js in your page and pass in the third argument to the animation function:

     $('html,body').animate({scrollTop: $("#"+id).offset().top}, 700, "easeInOutCirc");