停用图库滑块上的按钮

时间:2011-05-24 12:47:37

标签: javascript

当我到达滚动图像的末尾时,我正在尝试使我的javascript / jquery滑块按钮停用(当图像一直向右移动时,必须停用MoveRight按钮并且只保留MoveLeft按钮激活,同样为移动LeftButton),任何人都可以帮忙吗?我不确定我是否正在使用 .attr()和removeAttr()正确。我在下面粘贴了我的代码。

<script type="text/javascript">
$(document).ready(function(){

//Check width of Gallery div
var galleryWidth = $("#Gallery").innerWidth();
//Check width of GalleryItem
var NoListed = $("ul.GalleryItem li").length;
var galleryItemWidth = 1881;    

$('.MoveRight')
$('.GalleryItem').css('width', galleryItemWidth);

//Check width of Gallery div on resize
$(window).resize(function(){
    var galleryWidth = $("#Gallery").innerWidth();
  });

$('.MoveLeft').click(function() {
  $(".GalleryItem2").animate({"left": "-=350px"}, "slow");
  $(".GalleryItem3").animate({"left": "-=280px"}, "slow");
  $(".GalleryItem").animate({
    left: '-=230',
  }, "slow", function() {
    position = $(".GalleryItem").position();
    galleryItemLeft = position.left;
    if(galleryItemLeft <= galleryWidth - galleryItemWidth) {
        $('.MoveLeft').removeAttr('disabled');}
        else{
        $('.MoveLeft').attr('disabled','disabled');
        $('.MoveRight').attr('disabled','disabled');
    }
  });
});

$('.MoveRight').click(function() {
  $(".GalleryItem2").animate({"left": "+=350px"}, "slow");
  $(".GalleryItem3").animate({"left": "+=280px"}, "slow");
  $(".GalleryItem").animate({
    left: '+=230',
  }, "slow", function() {
    position = $(".GalleryItem").position();
    galleryItemLeft = position.left;
    if(galleryItemLeft >= "0") { 
        $('.MoveLeft').removeAttr('disabled');}
        else{
        $('.MoveLeft').attr('disabled','disabled');
        $('.MoveRight').attr('disabled','disabled');
    }   
  });
});

});


</script>

1 个答案:

答案 0 :(得分:0)

Okey,首先删除这个逗号;

left: '-=230',
-------------^

并在此处添加px

left: '-=230px'
------------^

然后尝试添加此内容;

if(galleryItemLeft <= 0) { 
    return false;
}

$('.MoveLeft').click(function() {之后 和正确的一样