【发布时间】:2011-04-08 19:24:29
【问题描述】:
大家好,它是典型的滑块 - 由用户点击自动控制和控制。问题是当你点击时,如果你在最后一张幻灯片上,它不应该显示右箭头,如果你在第一张幻灯片上,它不应该显示左箭头。如果您在其他任何地方,它应该显示两个箭头。但是,当在最后一张幻灯片上时,它仍然显示向右箭头。但是,在第一张幻灯片上,它正确地不显示左箭头。但是当你进入中间幻灯片时,它不会带回右箭头:
$(".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 语句中的“默认”是强制性的吗?
-
我没有收到任何错误。我所知道的是,当我在最后一张幻灯片上时,左箭头不会消失,它应该基于 switch 语句。在第一张幻灯片上,左箭头会消失,但在第二张幻灯片上,左箭头不会回来。
-
@Stephen 不,
default大小写不是强制性的。
标签: javascript jquery slider hide show