我已经使用 jQuery 完成了带有上一个和下一个按钮的图像幻灯片放映的完整箱。我觉得这个Demo应该对你有帮助,所以demo链接如下。
演示: http ://codebins.com/bin/4ldqp8x
HTML:
<div class="topbar">
<ul id="navigation">
<li id="previous">
<a href="#tag">
Previous
</a>
</li>
<li class="active">
<a href="#">
1
</a>
</li>
<li>
<a href="#">
2
</a>
</li>
<li>
<a href="#">
3
</a>
</li>
<li>
<a href="#">
4
</a>
</li>
<li>
<a href="#">
5
</a>
</li>
<li>
<a href="#">
6
</a>
</li>
<li>
<a href="#">
7
</a>
</li>
<li>
<a href="#">
8
</a>
</li>
<li>
<a href="#">
9
</a>
</li>
<li>
<a href="#">
10
</a>
</li>
<li id="next">
<a href="#tag">
Next
</a>
</li>
</ul>
</div>
<div id="images">
<div class="slide">
<img src="http://thumbs.myopera.com/sz/colx/Mathilda%C2%B4s%20Wallpaper/albums/104123/Animal%20Friends.jpg" width="250" height="200" />
</div>
<div class="slide">
<img src="http://marowall.ru/Jivotnie/Grizuni/Kroliki1024/8/9.jpg" width="250" height="200" />
</div>
<div class="slide">
<img src="http://www.mejoresmascotas.com/wp-content/uploads/2009/02/perrito.jpg" width="250" height="200" />
</div>
<div class="slide">
<img src="http://data.whicdn.com/images/16010691/white_lion_large.jpg" width="250" height="200" />
</div>
<div class="slide">
<img src="http://koprol.zenfs.com/system/mugshots/0153/9924/index.jpg" width="250" height="200" />
</div>
<div class="slide">
<img src="http://cdn.cutestpaw.com/wp-content/uploads/2011/11/Cute-Squirrel-s.jpg" width="250" height="200" />
</div>
<div class="slide">
<img src="http://thumbs.myopera.com/sz/colx/adilsaadi/albums/5861552/horses.jpg" width="250" height="200" />
</div>
<div class="slide">
<img src="http://fundartspring2011.wikispaces.com/file/view/puppy_dogs_14.jpg/217071218/297x225/puppy_dogs_14.jpg" width="250" height="200" />
</div>
<div class="slide">
<img src="http://1.bp.blogspot.com/-zfT5EAh0Tz8/TbJVRf5wywI/AAAAAAAAAE4/TWWdSLhx9Io/s1600/ardilla.jpg" width="250" height="200" />
</div>
<div class="slide">
<img src="http://thumbs.myopera.com/sz/colx/skafridi/albums/6474892/animals-pictures-birds-bluebird.jpg" width="250" height="200" />
</div>
</div>
CSS:
.topbar{
position:fixed;
top:0;
left:0;
height:35px;
background:none repeat scroll 0 0 #B0832E;
border-shadow:1px 0 4px rgba(0, 0, 0, 0.4);
font-size:12px;
width:100%;
z-index:9999;
}
#navigation{
border: 1px solid red;
list-style: none outside none;
margin: 5px auto 0;
text-align: center;
width: 60%;
z-index: 3;
}
#navigation li{
display:inline-block;
background:none repeat scroll 0 0 rgba(255, 255, 255, 0.9);
box-shadow:1px 1px 2px rgba(0, 0, 0, 0.2);
border:1px solid white;
color:#444444;
font-size:12px;
text-transform:uppercase;
}
#navigation li a{
color:#444444;
text-decoration:none;
padding:2px 5px;
}
#navigation li.active a, #navigation li:hover a{
color:#fff;
background:#333;
text-decoration:underline;
}
#images{
text-align:center;
}
.slide{
padding:5px;
display:none;
position:absolute;
top:35;
margin-left:25%;
background:#2255a9;
}
jQuery:
$(function() {
//Show Current Active Image Slide On Document Ready
showSlide();
$("li", $("#navigation")).click(function() {
var activeIndex = $("li.active", $("#navigation")).index();
if (typeof $(this).attr('id') != "undefined") {
if ($(this).attr('id') == "previous" && activeIndex > 1) {
//set PREV Active Image
$("li", $("#navigation")).removeClass('active');
$("#navigation li:eq(" + (activeIndex - 1) + ")").attr('class', 'active');
} else if ($(this).attr('id') == "next" && activeIndex < ($("li", $("#navigation")).length - 2)) {
//set NEXT Active Image
$("li", $("#navigation")).removeClass('active');
$("#navigation li:eq(" + (activeIndex + 1) + ")").attr('class', 'active');
}
} else {
//set Active Image which slide no is clicked
$("li", $("#navigation")).removeClass('active');
$(this).attr('class', 'active');
}
//Check if Different Slide has been clicked or Move then only load..
if (activeIndex != $("li.active", $("#navigation")).index()) {
showSlide(); //Call to show active image
}
});
});
//Function to Show Current Active Image Slide
function showSlide() {
//Get Current Index of Active LI
var i = $("li.active", $("#navigation")).index();
//Check Range of Current Index
if (i > 0 && i < ($("li", $("#navigation")).length - 1)) {
//FadeOut all Images
$(".slide", $("#images")).fadeOut(1000);
//FadeIn Only Current Active Indexed Slided
$(".slide:eq(" + (i - 1) + ")", $("#images")).fadeIn(3000);
}
}
演示: http ://codebins.com/bin/4ldqp8x