我制作了一个图片轮播
看我的小提琴:https://jsfiddle.net/gd2n6paw/8/
我是jquery的新手,只是想知道我们怎样才能制作旋转木马' next'和' prev'控制感谢您的帮助。
你也可以在这里看到我的代码:
我的HTML
<div class="slider">
<div class="container" id="img-slider">
</div>
</div>
<button onclick="prev()">
prev
</button>
<button onclick="next()">
next
</button>
我的css
.slider{
min-height:300px;
max-width:400px;
border:1px solid #000;`
}
.container{
background-image:url('http://www.xenergie.com/wp-content/uploads/2015/05/nature.jpg');
min-height:300px;
max-width:400px;
}
我的jQuery
(function(){
// main image carousel index.html you can customize it ...
var imgSlider = $('#img-slider');
var counter = 0;
var imgSliderContainer = ['http://www.xenergie.com/wp-content/uploads/2015/05/nature.jpg','http://www.pycomall.com/images/P1/Natural_Background.jpg','http://www.gochecks.net/data/media/91/Mobile_Nature_Wallpapers_35.jpg'];
function ImageSliderHome(){
imgSlider.fadeOut('5000' ,function(){
imgSlider.css('background-image', "url('" + imgSliderContainer[counter] + "')");
}).fadeIn('5000');
counter++;
if(counter >= imgSliderContainer.length){
counter = 0;
}
}
function prev(){
?
}
function next(){
?
}
setInterval(ImageSliderHome,3000);
})();
答案 0 :(得分:1)
这个怎么样?
https://jsfiddle.net/gd2n6paw/12/
$('#next').click(function(){
counter++;
ImageSliderHome();
});
$('#prev').click(function(){
if(counter == 0)
counter = imgSliderContainer.length;
else
counter--;
ImageSliderHome();
});