Jquery animate or easy left scroll

$(document).ready(function(){
    $("#right_arrow").click(function(e) {
        var scrollleftvar = $(window).scrollLeft();
        e.preventDefault()
        $("body").scrollLeft(scrollleftvar + 50);
    });
});

Hi, I am trying to revive or loosen the incremental scrollable eleft given above, but struggling a bit, any help would really be appreciated, thanks

+5
source share
1 answer

You can use the .animate()-function:

$('body').animate( { scrollLeft: '+=50' }, 1000, 'easeOutQuad' );
  • The first parameter sets the value that you want to animate. You can use something like +=valueor -=valueto animate from the current value (like offset).
  • The second parameter is the start time of the animation.
  • And the third is easing if you use the easing plugin.

See jQuery-Docs: ".animate ()" for more details .

+23
source

All Articles