京东轮播图
2016-02-21 21:27
591 查看
实例演示地址:https://liujie1990.github.io/myWork/luobotu/myindex.html
<script type="text/javascript"> function $(id){ return document.getElementById(id); } var oDiv=$("wrap"); var pic=$("pic").getElementsByTagName("li"); var num=$("num").getElementsByTagName("li"); var left=$("left"); var right=$("right"); var index=0; var len=pic.length; left.onclick=function(){ index--; if(index<0){ index=len-1; } change(index); }; right.onclick=function(){ index++; if(index>len-1){ index=0; } change(index); }; oDiv.onmouseover=function(){ clearInterval(timer); }; oDiv.onmouseout=function(){ timer=setInterval(run,2000); }; timer=setInterval(run,2000); function run(){ index++; if(index>len-1){ index=0; } change(index); } function change(curindex){ for(var i=0;i<len;i++){ pic[i].style.display="none"; num[i].className=""; } pic[curindex].style.display="block"; num[curindex].className="active"; } </script>
<div id="wrap"> <ul id="pic"> <li style="display: block;"><img src="img/1.jpg" alt=""></li> <li><img src="img/2.jpg" alt=""></li> <li><img src="img/3.jpg" alt=""></li> <li><img src="img/4.jpg" alt=""></li> <li><img src="img/5.jpg" alt=""></li> </ul> <ul id="num"> <li class="active">1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> </ul> <a href="javascript:;" class="arrow" id="left"><</a> <a href="javascript:;" class="arrow" id="right">></a> </div>
*{margin: 0;padding: 0;list-style: none;} a{text-decoration: none;color: #fff;} #wrap{width: 600px;height: 400px;margin: 100px auto;position: relative;cursor: pointer;} #pic li{display: none;position: absolute;top: 0;left: 0;z-index: 1;} #num{position: absolute;z-index: 2;bottom: 10px;left: 40%;} #num li{float: left;width: 20px;height: 20px;margin:3px;border-radius: 50%;line-height: 20px;color: #fff;background: #666;text-align: center;} #num li.active{background:#f00; } .arrow{z-index: 3;height: 40px;width: 30px;position: absolute;top: 45%;line-height: 40px;background: rgba(0,0,0,0.3);text-align: center;display: none;} .arrow:hover{background: rgba(0,0,0,0.7);} #wrap:hover .arrow{display: block;} #left{left:2%;} #right{right:2%;}
相关文章推荐
- 接口和抽象类的区别
- ajax——用ajax写登陆页面
- 【BZOJ3598】【SCOI2014】方伯伯的商场之旅
- Ubuntu14.04下安装Caffe总结
- 设计模式——职责链模式
- 官网下载旧版本的Xcode
- [Scala函数特性系列]——高阶函数
- 数据挖掘软件 clementine软件的基本操作
- 浅谈三层架构
- 栈和队列相关问题
- Mininet+opendaylight安装过程记录
- iOS的扩展类,扩展属性
- iOS NSUserDefaults的基本使用
- 【bzoj1305】[CQOI2009]dance跳舞 最大流+二分答案
- window系统LMAP(mysql+apache+php+wordpress)配置+web弹性托管+个人博客
- iOS-UI-基本控件之UITextField
- POJ 1502 - MPI Maelstrom
- CSS 巧用 :before和:after
- cocos 3D 光照
- 构建微服务-第一章-什么是微服务_001概览