一种可能的解决方案(存在多种解决方案):
演示
html
<a href="#" class="prev_p">Previous</a>
<a href="#" class="start">Start</a>
<a href="#" class="next_p">Next</a>
<div id="projects">
<div class="slide gray"></div>
<div class="slide white"></div>
<div class="slide black"></div>
<div class="slide gray"></div>
<div class="slide white"></div>
<div class="slide black"></div>
</div>
CSS
#projects {
position:relative;
float:left;
width:9800px;
height:300px;
overflow:hidden;
}
.slide {
position:relative;
float:left;
border:1px solid black;
width:1960px;
height:300px;
}
.gray {
background-color:gray;
}
.white {
background-color:white;
}
.black {
background-color:black;
}
jQuery
$(function () {
$(".prev_p").hide();
$(".start").hide();
var slidewidth = 1960; //in Pixels
var animationSpeed = 300; //in Milliseconds
//start page
$(".start").click(function () {
$("#projects").animate({
marginLeft: "0px"
}, animationSpeed, function () {
$(".start").hide();
$(".prev_p").hide();
$(".next_p").show();
});
});
//next page
$(".next_p").click(function () {
$("#projects").animate({
marginLeft: "-=" + slidewidth + "px"
}, animationSpeed, function () {
//check location after animation and hide controls
//that no longer serve a purpose and add those that do
var marginLeft = $("#projects").css("margin-left");
var numberOfSlides = 5;
if (marginLeft == "-" + (slidewidth * (numberOfSlides - 2)) + "px") {
$(".next_p").hide();
}
if (marginLeft != "0px") $(".start").show();
else $(".start").hide();
$(".prev_p").show();
});
});
//previous page
$(".prev_p").click(function () {
$("#projects").animate({
marginLeft: "+=" + slidewidth + "px"
}, animationSpeed, function () {
//check location after animation and hide controls
//that no longer serve a purpose and add those that do
var marginLeft = $("#projects").css("margin-left");
if (marginLeft == "0px") {
$(".prev_p").hide();
$(".start").hide();
} else {
$(".start").show();
}
$(".next_p").show();
});
});
});