2011-05-24 75 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