Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.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_Horizontal Scrolling - Fatal编程技术网

jQuery水平滚动动画

jQuery水平滚动动画,jquery,horizontal-scrolling,Jquery,Horizontal Scrolling,这可能是一个非常基本的问题,因为我是jQuery的不速之客,所以我不知道这一点 我有一个很宽的网站,所有内容都是水平排列的。我没有在底部使用滚动条,而是在两侧都有一个按钮,这样当你点击它时,它会在站点中向左或向右移动你 我这里有jQuery: $(".timeline_page a.flex-prev").click(function(){ $(".timeline_page_wrapper").scrollLeft(Math.max(0, $(".timeline_page_wrapper")

这可能是一个非常基本的问题,因为我是jQuery的不速之客,所以我不知道这一点

我有一个很宽的网站,所有内容都是水平排列的。我没有在底部使用滚动条,而是在两侧都有一个按钮,这样当你点击它时,它会在站点中向左或向右移动你

我这里有jQuery:

$(".timeline_page a.flex-prev").click(function(){
$(".timeline_page_wrapper").scrollLeft(Math.max(0, $(".timeline_page_wrapper").scrollLeft() - 500));
});

$(".timeline_page a.flex-next").click(function(){
$(".timeline_page_wrapper").scrollLeft(Math.min(1200, $(".timeline_page_wrapper").scrollLeft() + 500));
});
到目前为止还不错。但是我想给它做动画,我不知道怎么做。我尝试的每件事都会导致它无法运行

在相关注释中,是否有一种方法可以让我知道用户何时位于右侧或左侧的末端,以便我可以更改按钮状态

编辑:

好的,现在我有了下面的代码,并成功地制作了动画。但是,如果类达到某一点,我添加或删除它有什么错呢

$(".timeline_page a.flex-prev").click(function(){
$(".timeline_page_wrapper").animate({
    scrollLeft: Math.max(0, $(".timeline_page_wrapper").scrollLeft() - 500)}, 650);
});

$(".timeline_page a.flex-next").click(function(){
$(".timeline_page_wrapper").animate({
    scrollLeft: Math.min(4080, $(".timeline_page_wrapper").scrollLeft() + 500)}, 650);
});

if ($(".timeline_page_wrapper").scrollLeft() === 0 {
    $(".timeline_page a.flex-prev").addClass("flex-disabled");
} else {
    $(".timeline_page a.flex-prev").removeClass("flex-disabled");
}
);

});

我以前用过,而且很有效!请参阅和此处。

查看JQuery Animate()方法。尝试以视图/页面宽度的增量设置位置动画。

通过检查timeline_page_包装器的scrollLeft()并将其与整个内容宽度进行比较,可以判断用户已到了结尾。Scrollleft还应提供要显示的剩余金额。一个小算术将告诉你是否已经到了这一页的末尾。

希望这有帮助