嘿所有,它的典型滑塊 - 既可以自動控制,也可以通過用戶單擊進行控制。問題在於當你點擊時,如果你在上一張幻燈片上,它不應該顯示右箭頭,並且如果你在第一張幻燈片上,它不應該顯示左箭頭。如果你在其他地方,它應該顯示兩個箭頭。但是,在上一張幻燈片中,它仍然顯示右箭頭。但是,在第一張幻燈片上時,它不會顯示左箭頭。但是當你到中間的幻燈片,它不帶回右箭頭:誰能告訴我這個switch語句(javascript)有什麼問題?
$(".paging").show();
$(".image_reel img:first").addClass("active");
$active = $(".image_reel img:first");
var imageWidth = $(".window").width();
var imageSum = $(".image_reel img").size();
var imageReelWidth = imageWidth * imageSum;
$(".image_reel").css({'width' : imageReelWidth});
rotate = function(){
var triggerId = $active.attr('src').substring(7,8);
var image_reelPosition = (triggerId - 1) * imageWidth;
$(".image_reel img").removeClass("active");
$active.addClass("active");
switch ($active.attr('src')) {
case "images/4.png":
var $lastPic = $active.attr("src");
manageControls($lastPic);
break;
case "images/1.png":
var $firstPic = $active.attr('src');
manageControls($firstPic);
break;
case "image/2.png":
var $standardPic = $active.attr('src');
manageControls($standardPic);
break;
case "image/3.png":
var $standardPic = $actice.attr('src');
manageControls($standardPic);
break;
}
$(".image_reel").animate({
left: -image_reelPosition
}, 500);
};
rotateSwitch = function(){
play = setInterval(function(){
if(!$(".paging a").show()) $(".paging a").show(); //This is CRITICAL - this makes sure the arrows reappear after they have been removed
$active = $(".image_reel img.active").parent().next().find("img");
if ($active.length === 0){
$active = $('.image_reel img:first');
var $firstPic = $active.attr("src");
manageControls($firstPic);
}
rotate();
}, 5000);
};
rotateSwitch();
$(".paging a").click(function(){
$active = ($(this).attr('id')=='rightCtr') ? $(".image_reel img.active").parent().next().find('img') : $(".image_reel img.active").parent().prev().find('img');
if ($active.length === 0){
$active = $('.image_reel img:first');
}
clearInterval(play);
rotate();
rotateSwitch();
return false;
});
manageControls = function(whichImg){
(whichImg == "images/4.png") ? $(".paging a#rightCtr").hide() : $(".paging a#rightCtr").show();
(whichImg == "images/1.png") ? $(".paging a#leftCtr").hide() : $(".paging a#rightCtr").show();
if(whichImg != "images/1.png" || whichImg != "images/4.png"){
$(".paging a#rightCtr").show();
$(".paging a#rightCtr").show();
}
};
HTML:
<div class="window">
<div class="image_reel">
<a href="#"><img src="images/1.png" alt="" /></a>
<a href="#"><img src="images/2.png" alt="" /></a>
<a href="#"><img src="images/3.png" alt="" /></a>
<a href="#"><img src="images/4.png" alt="" /></a>
</div>
</div>
<div class="paging">
<a href="#" id="leftCtr">Left</a>
<a href="#" id="rightCtr">Right</a>
</div>
</div>
感謝任何迴應。
你從錯誤控制檯得到什麼輸出?另外,在javascript switch語句中,「default」是強制的嗎? – Stephen 2010-09-06 14:30:32
我沒有得到任何錯誤。我所知道的是,當我在上一張幻燈片中時,左箭頭不會消失,它應該基於開關狀態。在第一張幻燈片上,左箭頭確實消失,但在第二張幻燈片上時,左箭頭不會返回。 – JohnMerlino 2010-09-06 14:36:57
@Stephen no,默認情況下不是強制性的。 – Pointy 2010-09-06 14:40:37