我做了一些下面的脚本来制作简单的淡入淡出幻灯片。现在我想添加 Next/Prv 按钮。我该怎么做?
下面是我的 HTML:
<body>
<div id="slider-main-part">
<img class="slider-img" src="images/slider01.jpg" />
<img class="slider-img" src="images/slider02.jpg" />
<img class="slider-img" src="images/slider03.jpg" />
<img class="slider-img" src="images/slider04.jpg" />
</div>
</body>
下面是我的 JavaScript/jQuery:
$(document).ready(function (e) {
var slider = {
init: function () {
var initialFadeIn = 1000;
var itemInterval = 5000;
var fadeOut = 2500;
var numberOfItems = $('.slider-img').length;
var currentItem = 0;
//show first item
$('.slider-img').eq(currentItem).fadeIn(initialFadeIn);
//loop through the items
var infiniteLoop = setInterval(function () {
$('.slider-img').eq(currentItem).fadeOut(fadeOut);
if (currentItem == numberOfItems - 1) {
currentItem = 0;
} else {
currentItem++;
}
$('.slider-img').eq(currentItem).fadeIn(fadeOut);
}, itemInterval);
}
};
slider.init();
});
在这里,我在下面附上我的 CSS:
#slider-main-part {
position: relative;
zoom:1;
margin:auto;
width:980px;
}
.slider-img {
display: none;
position: absolute;
top: 0;
left: 0;
width:980px;
border:none;
height:551px;
}