jQuery jquery动画或缓动向左滚动增量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11967107/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 11:09:27  来源:igfitidea点击:

jquery animate or ease scroll left increment

jqueryscrolljquery-animate

提问by gilesadamthomas

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

Hi, Im trying to animate or ease the incremental scroll eleft triggered above, but struggling a little, any help would be really appreciated, thank you

嗨,我试图动画或缓解上面触发的增量滚动 eleft,但有点挣扎,任何帮助将不胜感激,谢谢

回答by insertusernamehere

You can use the .animate()-function:

您可以使用.animate()- 功能:

$('body').animate( { scrollLeft: '+=50' }, 1000, 'easeOutQuad' );
  • The first parameter sets the value you want to animate. You can use something like +=valueor -=valueto animate from the current value (like an offset).
  • The second parameter is the time the animation is running.
  • And the third is the easing, if you're using an easing plug-in.
  • 第一个参数设置要设置动画的值。您可以使用类似+=value-=value从当前值(如偏移量)设置动画。
  • 第二个参数是动画运行的时间。
  • 第三个是缓动,如果您使用缓动插件。

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

有关更多信息,请参阅jQuery-Docs:“.animate()”

回答by KR Vineeth

I think it works fine:

我认为它工作正常:

$('.tag-container').animate({scrollLeft:'+=300'}, 1000, "swing");

use swingmethod instead of easeOutQuad.

使用swing方法而不是easeOutQuad.