我一直在搜索,但是我在文档中找不到关于这个的任何东西,除非我遗漏了什么。我使用这个简单的DIY滑翔机http://jsfiddle.net/kGRRK/,我想让它显示当前的幻灯片。
如下所示:
3中的5
或者这个:
- -X- -
这里有一个简单的代码行来实现这一点吗?
$(".slider").diyslider({
width: "400px",
height: "200px",
display: 1,
loop: false,
});
$(".current-slide")
// use buttons to change slide
$("#go-left").bind("click", function(){
$(".slider").diyslider("move", "back");
});
$("#go-right").bind("click", function(){
$(".slider").diyslider("move", "forth");
});发布于 2014-02-21 05:31:45
试试这边
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/
快乐编码:)
https://stackoverflow.com/questions/21880583
复制相似问题