我一直在玩它,我的代码绝对不是最有效的方法,但它可以完成工作......
我的方法如下:
=> 任何三张放映幻灯片的 z-index 必须高于其他幻灯片,并且当前放映幻灯片的 z-index 会随着您单击“上一个”或“下一个”按钮而增加。
=>特殊情况是中间幻灯片的索引是'0'或'6'。假设您的中间幻灯片在单击“下一步”按钮六次后现在为“0”。幻灯片 '1' 和 '6' 的 z-index 将与幻灯片 '0' 具有相同的度数,太棒了!但是当您单击“上一个”按钮时发生了什么?幻灯片 '0' 的 z-index 实际上低于幻灯片 '1'。因此,必须对“0”(第一张)和“6”(最后一张)目标幻灯片进行特殊处理。
希望这可以帮助 :)
//JQuery
window.mySwipe = $('#mySwipe').Swipe().data('Swipe');
var numClick = 0;
$("#next").bind('click',function(){
numClick += 1;
indexSwipe = mySwipe.getPos();
curIndex = "#index"+indexSwipe;
preIndex = "#index"+(indexSwipe-1);
nextIndex = "#index"+(indexSwipe+1);
if(indexSwipe == 0){
$(curIndex).css("z-index",numClick);
$("#index6").css("z-index",numClick);
$(nextIndex).css("z-index",numClick);
}else if(indexSwipe == 6){
$(curIndex).css("z-index",numClick);
$("#index5").css("z-index",numClick);
$("#index0").css("z-index",numClick);
}else{
$(indexSwipe).css("z-index",numClick);
$(preIndex).css("z-index",numClick);
$(nextIndex).css("z-index",numClick);
}
});
$("#prev").bind('click',function(){
numClick += 1;
indexSwipe = mySwipe.getPos();
curIndex = "#index"+indexSwipe;
preIndex = "#index"+(indexSwipe-1);
nextIndex = "#index"+(indexSwipe+1);
if(indexSwipe == 0){
$(curIndex).css("z-index",numClick);
$("#index6").css("z-index",numClick);
$(nextIndex).css("z-index",numClick);
}else if(indexSwipe == 6){
$(curIndex).css("z-index",numClick);
$("#index5").css("z-index",numClick);
$("#index0").css("z-index",numClick);
}else{
$(indexSwipe).css("z-index",numClick);
$(preIndex).css("z-index",numClick);
$(nextIndex).css("z-index",numClick);
}
});
<!--HTML-->
<div style='text-align:center;padding:5px 0px;'>
<button id="prev" onclick='mySwipe.prev();return false;'><</button>
<button id="next" onclick='mySwipe.next();return false;'>></button>
</div>
<div id='myWrapper'>
<div id='mySwipe' style='max-width:300px;margin:0 auto' class='swipe'>
<div class='swipe-wrap'>
<div id="index0"><b>0</b></div>
<div id="index1" style="z-index:1;"><b>1</b></div>
<div id="index2"><b>2</b></div>
<div id="index3"><b>3</b></div>
<div id="index4"><b>4</b></div>
<div id="index5"><b>5</b></div>
<div id="index6"><b>6</b></div>
</div>
</div>
</div><!-- /myWrapper -->
<-- .css -->
.swipe {
overflow: visible;
visibility: hidden;
position: relative;
}
.swipe-wrap {
overflow: visible;
position: relative;
}
.swipe-wrap > div {
float:left;
width:100%;
position: relative;
}
#myWrapper{
overflow: hidden;
visibility: visible;
width: 620px;
}