Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery:按一定数量设置向左滚动的动画_Jquery_Scroll_Jquery Animate - Fatal编程技术网

Jquery:按一定数量设置向左滚动的动画

Jquery:按一定数量设置向左滚动的动画,jquery,scroll,jquery-animate,Jquery,Scroll,Jquery Animate,现在从开始滚动到特定位置100px。如何表达这一点,使每次点击scrollbutton时,它向左滚动100px 提前感谢。试试这个: var xxx= 100px; $(".scrollbutton").click(function () { $('.selector').animate({scrollLeft:xxx)}, 500); }); 我建议采取以下解决办法: var xxx= 100; $(".scrollbutton").click(function () {

现在从开始滚动到特定位置100px。如何表达这一点,使每次点击scrollbutton时,它向左滚动100px

提前感谢。

试试这个:

var xxx= 100px;

$(".scrollbutton").click(function () { 
    $('.selector').animate({scrollLeft:xxx)}, 500);
});

我建议采取以下解决办法:

var xxx= 100;

$(".scrollbutton").click(function () { 
    $('.selector').animate({scrollLeft:"+="+xxx)}, 500);
});
工作小提琴:


基于
.animate()
的jQuery文档:

动画属性也可以是相对的。如果为值提供了前导的+=-=字符序列,则通过从属性的当前值添加减去给定数字来计算目标值

例如:

[…]左:“+=50”,[…]

var scrollLeftAmount = 100;
$('.scrollbutton').click(function () { 
    $('.selector').animate({
        scrollLeft:'+='+scrollLeftAmount
    },500);
});