Javascript 需要使用jquery更改滑块

Javascript 需要使用jquery更改滑块,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我有一个简单的滑块,我想显示图像的左侧和右侧的默认图像,并滚动左右按钮 当前设置: 下面是我滑动图像的代码,但它仅在图像从右向左滑动时才能正常工作,如何使其在从左向右滑动时工作,并在滑动前使左侧的图像可见 $(document).ready(function() { $("#btnRight").click(function(){ $('#carousel ul').animate({marginLeft:'-=810px'}, 1000, function(){ $(this).f

我有一个简单的滑块,我想显示图像的左侧和右侧的默认图像,并滚动左右按钮

当前设置:

下面是我滑动图像的代码,但它仅在图像从右向左滑动时才能正常工作,如何使其在从左向右滑动时工作,并在滑动前使左侧的图像可见

$(document).ready(function() {

$("#btnRight").click(function(){
$('#carousel ul').animate({marginLeft:'-=810px'}, 1000, function(){

    $(this).find("li:last").after($(this).find("li:first"));
    $(this).css({marginLeft:0});
});
});
});

$(document).ready(function() {

$("#btnLeft").click(function(){
$('#carousel ul').animate({marginLeft:'+=810px'}, 1000, function(){

    $(this).find("li:last").after($(this).find("li:first"));
    $(this).css({marginLeft:0});
});
});
});
试试这个

$(document).ready(function() {
  $("#btnRight").click(function(){
    $('#carousel ul').animate({marginLeft:'-=810px'}, 1000, function(){
        $(this).find("li:last").after($(this).find("li:first"));
        $(this).css({marginLeft:0});
    });
  });
  $("#btnLeft").click(function(){
    $('#carousel ul li:first').before($("#carousel ul").find("li:last"));
    $('#carousel ul').css({"margin-left":"-810px"});
    $('#carousel ul').animate({marginLeft:'+=810px'}, 1000, function(){
        $(this).css({marginLeft:0});
    });
  });
});

非常适合向左滚动,谢谢。您知道是否可以将其向左移动810px,以便可以看到左右两侧的图像吗?