2017.09.03
Check Out
New
jQuery 制作轮播图 Demo
<div class="out">
<ul class="img">
<li><a href="#"><img src="images/1.jpg" alt=""></a></li>
<li><a href="#"><img src="images/2.jpg" alt=""></a></li>
<li><a href="#"><img src="images/3.jpg" alt=""></a></li>
<li><a href="#"><img src="images/4.jpg" alt=""></a></li>
<li><a href="#"><img src="images/5.jpg" alt=""></a></li>
</ul>
<ul class="num">
<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>
</ul>
<div class="left-btn"><</div>
<div class="right-btn">&gh;</div>
</div>
<script>
$(function(){
var $imageList = $('.img li');
var $numList = $('.num li');
var $out = $('.out');
$imageList.eq(0).show();
$numList.mouseover(function(){
i = $(this).index();
changeSlider(index);
});
var changeSlider = function(showIndex) {
$numList.eq(showIndex).addClass('active').siblings().removeClass('active');
$imageList.eq(showIndex).stop().fadeIn(300).siblings().stop().fadeOut();
};
var moveToRight = function(){
i++;
if( i==5 ) i = 0;
changeSlider(i);
};
var moveToLeft = function() {
i--;
if( i==-1 ) i = 4;
changeSlider(i);
}
var i = 0;
var t = setInterval(moveToRight, 1500);
$out.hover(function() {
clearInterval(t);
}, function(){
t = setInterval(move, 1500);
});
$('.out .left').click(function(){
moveToLeft();
});
$('.out .right').click(function(){
moveToRight();
});
});
</script>