JQ轮播图

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
.slider{
width: 400px;
height: 400px;
overflow: hidden;
}
.slider .slides{
width: 6000px;
height: 400px;
}
.slider .slide{
float: left;
list-style-type: none;
width: 720px;
height: 400px;

}
.slider .slide img{
width:720px;
}
</style>
<link rel="stylesheet" href="css/bootstrap.min.css" />
<script src="js/jquery-2.1.1.min.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div class="container">
<div class="header">
<h1 class="text-muted">
jQuery Basic Slide
</h1>
</div>
<div class="slider">
<ul class="slides">
<li class="slide"><img src="img/1.jpg" alt="" /></li>
<li class="slide"><img src="img/2.jpg" alt="" /></li>
<li class="slide"><img src="img/3.jpg" alt="" /></li>
<li class="slide"><img src="img/4.jpg" alt="" /></li>
<li class="slide"><img src="img/1.jpg" alt="" /></li>
</ul>
</div>
</div>
<script type="text/javascript">
$(function(){
// 定义一个宽度
var width = 720;
//定义一个速度时间
var animateSpeed = 1000;
// 每隔多少秒调用一次
var pause = 3000;
// 获取大的div
var $slider = $('.slider');
// var $slideContainner = $('.slides');
var $slideContainer = $slider.find('.slides');
var $slides = $slideContainer.find('.slide');
var currentSlide = 1;
var interval;
function startSlide(){
interval=setInterval(function(){
$slideContainer.animate({'margin-left':'-='+width},
animateSpeed,function(){
currentSlide++;
if(currentSlide===$slides.length){
currentSlide=1;
$slideContainer.css('margin-left',0);
}
});

},pause)
};
// 鼠标移入移出事件
$slider.on('mouseenter',pauseSlider).on('mouseleave',
startSlide);
function pauseSlider(){
clearInterval(interval);
interval=null;
}
startSlide();

});
</script>
</body>
</html>

上一篇:vue项目一个页面使用多个轮播图详解


下一篇:第十届机器学习及其应用研讨会 MLA’2012 Slides