<!DOCTYPE html>
<html>
<head>
<title>ads</title>
<script src="../scripts/jquery.js" type="text/javascript"></script>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
ul,li {
list-style: none;
}
.banner {
position: relative;
width: 100%;
overflow: hidden;
}
.banner-list img {
display: none;
width: 100%;
}
.dot {
position: absolute;
bottom: 30px;
left: 50%;
margin-left: -86px;
z-index: 10;
}
.dot li {
float: left;
width: 20px;
height: 20px;
margin: 0 6px;
border-radius: 10px;
background: #fff;
opacity: 0.6;
}
.active {
opacity: 1!important;
}
</style>
</head>
<body>
<div class="banner">
<div class="banner-list">
<img src="images/ads/1.jpg" alt=""/>
<img src="images/ads/2.jpg" alt=""/>
<img src="images/ads/3.jpg" alt=""/>
<img src="images/ads/4.jpg" alt=""/>
<img src="images/ads/5.jpg" alt=""/>
</div>
<ul class="dot">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</div>
</div>
<script type="text/javascript">
$(function(){
//benner块高度
$(".banner-list").height($(".banner-list img").height());
var index = 0;
var adTimer = null;
//dot操作显示不同图片
$(".dot li").mouseover(function(){
imgLength = $(".banner-list img").length;
index=$(".dot li").index(this);
imgShow(index);
}).eq(0).mouseover();
//鼠标位于图片上停止轮播,鼠标离开图片开始轮播
$(".banner").hover(function(){
if(adTimer){
clearInterval(adTimer);
}
},function(){
adTimer = setInterval(function(){
imgShow(index);
index++;
if(index == imgLength){index = 0;}
},2000);
}).trigger("mouseleave");
//显示图片
function imgShow(index){
$(".banner-list img").eq(index).fadeIn().siblings().fadeOut();
$(".dot li").eq(index).addClass("active").siblings().removeClass("active");
}
})
</script>
</body>
</html>
jquery - 焦点图下标显示、自动轮播(下标手动)
最新推荐文章于 2021-09-04 15:58:11 发布