<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<meta charset="utf-8" />
<style>
.outer {
width: 586px;
height: 150px;
overflow: hidden;
position: relative;
}
.outer .imgs {
position: absolute;
top: 0;
}
.outer ul {
position: absolute;
padding: 0;
margin: 0;
list-style: none;
right: 20px;
bottom: 10px;
}
.outer ul li {
width: 10px;
height: 10px;
display: table-cell;
}
.outer ul li a {
border: 1px solid #ffd800;
color: #ffd800;
background-color: white;
padding: 0px 4px;
line-height: 10px;
font-size: 12px;
margin-right: 2px;
cursor:pointer;
}
.outer ul li a.active {
background-color: #ffd800;
color: white;
font-size: 16px;
}
</style>
</head>
<body>
<div class="outer">
<div class="imgs">
<img src="Images/1.gif" />
<img src="Images/2.gif" />
<img src="Images/3.gif" />
<img src="Images/4.gif" />
<img src="Images/5.gif" />
</div>
<ul>
<li><a class="active">1</a></li>
<li><a>2</a></li>
<li><a>3</a></li>
<li><a>4</a></li>
<li><a>5</a></li>
</ul>
</div>
<script src="Scripts/jquery.min.js"></script>
<script>
$(function () {
var interval = setInterval(play, 2000);
$('.outer').hover(function () {
clearInterval(interval);
},
function () {
interval = setInterval(play, 2000);
});
$('li').click(function () {
var index = $(this).index();
time = index-1;
play();
})
})
var time = 0;
function play() {
time++;
var num = $('.imgs').children().length
if (time <= num - 1)
$('.imgs').animate({ top: -155 * time }, 1000);
else {
time = 0;
$('.imgs').animate({ top: 0 }, 1000);
}
//切换按钮
$('li a').removeClass('active');
$('li a:eq(' + (time) + ')').addClass('active');
console.log(time);
}
</script>
</body>
</html>
网站图片轮播的使用方法,使用Jquery实现
最新推荐文章于 2024-11-01 10:15:45 发布