嘿所有,它的典型滑块 - 既可以自动控制,也可以通过用户单击进行控制。问题在于当你点击时,如果你在上一张幻灯片上,它不应该显示右箭头,并且如果你在第一张幻灯片上,它不应该显示左箭头。如果你在其他地方,它应该显示两个箭头。但是,在上一张幻灯片中,它仍然显示右箭头。但是,在第一张幻灯片上时,它不会显示左箭头。但是当你到中间的幻灯片,它不带回右箭头:谁能告诉我这个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