2011-05-24 81 views
0

我正试图让我的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> 
+0

那么究竟什么是你的结果呢? – 2011-05-24 13:17:29

+0

它向左和向右滑动,但是在遇到条件时没有按钮被禁用。 – Charl 2011-05-24 14:54:53

回答

0

Okey,以移除此逗号开头;

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

,并添加PX这里

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

然后尝试添加此这一点;

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

之后$('.MoveLeft').click(function() {
与同为正确的

+0

谢谢Johan。它对滑块没有影响。你的意思是把上面的条件放在函数内还是下面(后面)呢?任何其他想法? – Charl 2011-05-25 11:27:09

+0

就在你开始滑动之前,这样的功能将返回并跳过块的其余部分 – 2011-05-25 12:12:03

+0

当我在那里添加条件时,它导致滑块停止工作,它不再滑动。任何想法为什么? – Charl 2011-05-25 12:46:32