当前位置:Gxlcms > JavaScript > 关于焦点轮播图实例代码

关于焦点轮播图实例代码

时间:2021-07-01 10:21:17 帮助过:5人阅读

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>焦点轮播图效果</title>
<style type="text/css">
*{
margin: 0;
padding: 0;
list-style-type: none;
}
.wrap{
width:490px;
height: 170px;
margin: 100px auto;
overflow: hidden;
position: relative;
}
.wrap ul{
position: absolute;
}
.wrap li{
height: 170px;
}
.list{
position: absolute;
right: 10px;
bottom: 10px;
}
.list li{
float: left;
width: 20px;
height: 20px;
background-color: #ccc;
border: 1px solid #666;
margin-left: 5px;
color: #000;
text-align: center;
line-height: 20px;
cursor: pointer;
}
.list li.on{
background-color: #E57000;
color: #fff;
}
</style>
</head>
<body>
<div class="wrap" id="wrap">
<ul class="pic" id="pic">
<li><img src="http://img.mukewang.com/54111cd9000174cd04900170.jpg" alt="图1" /></li>
<li><img src="http://img.mukewang.com/54111dac000118af04900170.jpg" alt="图2" /></li>
<li><img src="http://img.mukewang.com/54111d9c0001998204900170.jpg" alt="图3" /></li>
<li><img src="http://img.mukewang.com/54111d8a0001f41704900170.jpg" alt="图4" /></li>
<li><img src="http://img.mukewang.com/54111d7d00018ba604900170.jpg" alt="图5" /></li>
</ul>
<ol class="list" id="list">
<li class="on">1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ol>
</div>
<script type="text/javascript">

window.onload=function () {
//获取元素,申明变量
var wrap=document.getElementById('wrap'),
pic=document.getElementById('pic'),
list=document.getElementById('list').getElementsByTagName('li');
var index=0,
that=this,
timer=null;

//绑定
function autoPlay(){
index++;
if (index>=list.length) {
index=0;
}
qiehuan(index);
}
timer=setInterval(autoPlay,2000);
//鼠标滑过整个容器时停止切换(定时器)
wrap.onmouseover=function(){
clearInterval(timer)
}
//鼠标离开时,继续切换
wrap.onmouseout=function(){
timer=setInterval(autoPlay,2000);
}

//遍历所有数字导航,实现滑过切换至对应得图片
for (var j = 0; j < list.length; j++) {
list[j].id=j;
list[j].onmouseover=function(){
qiehuan(this.id);
clearInterval(timer);
}
}


function qiehuan(num){
for (var i = 0; i < list.length; i++) {
list[i].className="";
}
list[num].className="on";
pic.style.top="-"+num*170+"px";
num=index;
}
}
</script>

</body>
</html>

以上就是关于焦点轮播图实例代码的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行