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
jquery animate or ease scroll left increment
提问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
+=value
or-=value
to 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 swing
method instead of easeOutQuad
.
使用swing
方法而不是easeOutQuad
.