您只需要这个简化的 HTML:
<div id="slideshow">
<div id="slidesContainer">
<div class="slide"><h2>Slide-1</h2></div>
<div class="slide"><h2>Slide-2</h2></div>
<div class="slide"><h2>Slide-3</h2></div>
<div class="slide"><h2>Slide-4</h2></div>
<div class="slide"><h2>Slide-5</h2></div>
<div class="slide"><h2>Slide-6</h2></div>
</div>
<div id="tabsstyle">
<ul></ul>
<div id="play_pause"></div>
</div>
添加+修改的CSS:
#tabsstyle li {
float:left;
list-style-type:none;
}
#tabsstyle li, #play_pause{
color:#999;
cursor:pointer;
background:#eee url(img/MenuIcon.png) no-repeat 0 0;
display:block;
width:35px;
height:20px;
text-align:center;
padding:8px 0;
margin: 0 10px;
-webkit-border-radius:4px;
border-radius:4px;
}
#tabsstyle li.active{
background:#cf5 url(img/MenuIcon.png) no-repeat 0 -35px;
}
#play_pause{
position:absolute;
line-height:16px;
font-weight:bold;
right:0px;
}
乐趣从这里开始:
var curr = 0; // SET DESIRED START SLIDE
var delay = 2500; // SET DELAY BETWEEN ANIMATIONS
var fadeTime = 700; // SET FADE TIME
var symb = [ '||' , '►' ]; // play-pause button symbols
// do not edit below this line :) //
var slides = $(".slide").length;
var inter;
$("#slidesContainer").css("overflow", "hidden");
$("#slidesContainer .slide").css('position','absolute').hide().eq(curr).show();
// CREATE BUTTONS /////////////////
for (i = 0; i < slides; i++){
$("#tabsstyle ul").append('<li>'+(i+1)+'</li>');
}
$('#tabsstyle ul li').eq(curr).addClass('active'); // first tab selected on doucment ready
// ////////////////////////////////
// OUR FUNCTIONS //////////////////
function anim(){
$('#tabsstyle li').eq(curr).addClass("active").siblings().removeClass('active'); // Set active btn
$('.slide').eq(curr).fadeIn(fadeTime).siblings().fadeOut(fadeTime); // Slides animation
}
function stop(){
clearInterval(interv); // stop auto-animation
interv = false;
$("#play_pause").html( symb[1] );
}
function play(){
interv = setInterval(function(){
curr = (++curr % slides);
anim();
},delay+fadeTime);
$("#play_pause").html( symb[0] );
}
// ///////////////////////////////
play(); // Start (at dom ready)
$("#tabsstyle").on("click", "li", function(){
stop(); // stop
curr = $(this).index(); // set current slide
anim(); // Run 'anim' function to 'curr' slide
});
$("#play_pause").on("click", function(){
var check= interv===false ? play() : stop();
});