嘗試這種方式
HTML代碼:
<button id="go-left">«</button>
<button id="go-right">»</button>
<div class="slider">
<!-- The slider -->
<div>
<!-- A mandatory div used by the slider -->
<!-- Each div below is considered a slide -->
<div class="a">Div #1</div>
<div class="b">Div #2</div>
<div class="c">Div #3</div>
<div class="d">Div #4</div>
<div class="e">Div #5</div>
</div>
</div>
<div id="counter">
<!-- counter --> <span class="current-slide"></span> of <span class="total-slides"></span>
</div>
<div class="currentSlide"><span class="cur-slide"></span>
</div>
JS代碼:
// hide the message when the slider ends moving, and update the counter
$(".slider").bind("moved.diyslider", function (event, slide, slideNumber) {
slideNo = "";
$("#counter .current-slide").text(slideNumber);
curSlide = $("#counter .total-slides").text();
index = 1;
while (index <= curSlide) {
if (index == slideNumber) slideNo += " " + slideNumber + " ";
else slideNo += " - ";
index++;
}
$(".cur-slide").text(slideNo);
});
// initialize the slider
$(".slider").diyslider({
width: "400px",
height: "200px",
display: 1,
loop: false,
start: 1
});
//set the slider index initially to first slide
$(".cur-slide").text("1 - - - -");
// set the counter's slides count once the slider has been initialized
$("#counter .total-slides").text($(".slider").diyslider("getSlidesCount"));
// use buttons to change slide
$("#go-left").bind("click", function() {
$(".slider").diyslider("move", "back");
});
$("#go-right").bind("click", function() {
$(".slider").diyslider("move", "forth");
});
CSS:
div {
color: #000;
font-size: 30px;
line-height: 1.5em;
font-weight: bold;
}
div.a {
background: red;
}
div.b {
background: green;
}
div.c {
background: orange;
}
div.d {
background: black;
color: #fff;
}
div.e {
background: pink;
}
.slider {
border: 3px solid #000;
}
現場演示:http://jsfiddle.net/dreamweiver/CGBVF/20/
編碼快樂:)
http://jsfiddle.net/pioul/ba5jh/?來自其他活動示例的第一個鏈接http://pioul.fr/jquery-diyslider? – sinisake
這是你想要的嗎?http://jsfiddle.net/bj4yZ/493/ – dreamweiver
謝謝一幫傢伙! @dreamweiver你的版本似乎工作,但它增加了一個幻燈片,而不是實際上。我結束了一個比我想象的簡單得多的代碼:http://jsfiddle.net/CGBVF/ 所以這就是我所需要的。出於好奇,有沒有辦法讓幻燈片顯示爲「 - - X - - 」,X標記當前幻燈片? – Pascal