封装的焦点轮播图代码
来源:互联网 发布:cf滑步教程 知乎 编辑:程序博客网 时间:2024/06/08 12:05
封装的焦点轮播图代码
<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>无标题文档</title><style>*{margin:0; padding:0;}ul,ol {list-style:none;}img {border:none;}.banner {height:320px; width:852px; position:relative; margin:30px auto;}.imgs li {height:320px; width:852px; position:absolute; left:0; top:0; opacity:0;}.nav {position:absolute; bottom:15px; right:15px;}.nav li {width:20px; height:20px; filter:alpha(opacity:60); opacity:0.6; background:#fff; z-index:3;color:#000; background:#fff; border:1px solid #000; font-size:12px; text-align:center; line-height:20px;font-weight:600; margin-left:2px; float:left; cursor:pointer;}.nav li.active {background:#000; border:1px solid #fff; color:#fff;}</style></head><body><div class="banner"> <ul class="imgs"> <li style="opacity:1;"><img src="img/1.png" /></li> <li><img src="img/2.jpg" /></li> <li><img src="img/3.jpg" /></li> <li><img src="img/4.jpg" /></li> <li><img src="img/5.jpg" /></li> </ul> <ul class="nav"> <li class="active">1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> </div></div></body></html><script type="text/javascript"> //getByClassfunction getByClass (obj, sCls){ var aEle=obj.getElementsByTagName("*"); var aResult=[]; var re=new RegExp("\\b"+sCls+"\\b", "i"); for(var p=0;p<aEle.length;p++){ if(re.test(aEle[p].className))aResult.push(aEle[p]); } return aResult; }//getStylefunction getStyle(obj, attr){ if(obj.currentStyle) { return obj.currentStyle[attr]; } else { return getComputedStyle(obj, false)[attr]; }}function Banner(){ //初始化 this.init.apply(this, arguments);}Banner.prototype={ init : function(options){ this.setOptions(options); this.aImg=this.options.img; this.aNav=this.options.nav; this.speed=this.options.speed; this.oBanner=this.options.banner; this.timer=null; this.fadeTimer=null; this.iNow=0; //当前图片 var that=this; this.timer=setInterval(function (){that.next()}, that.speed); //设置自动播放 this.oBanner.onmouseover=function(){clearInterval(that.timer)}; this.oBanner.onmouseout=function(){that.timer=setInterval(function (){that.next()}, that.speed)}; for(var i=0;i<this.aImg.length;i++){ this.aNav[i].index=i; //自定义属性 this.aNav[i].onclick=function(){that.iNow=this.index;that.turnImgs();}; } }, setOptions : function(options){ this.options={ img : this.aImg, //图片元素集合 nav : this.aNav, //按钮导航 banner : this.oBanner, //banner容器 speed : 5000 //切换间隔-->毫秒 }; for(var p in options)this.options[p]=options[p]; }, turnImgs : function(){ var that=this; for(var i=0;i<this.aImg.length;i++){ //this.aImg[i].style.opacity=0; //this.aImg[i].style.filter="alpha(opacity:0)"; fade(this.aImg[i], {opacity:0}) this.aNav[i].className=""; } fade(this.aImg[that.iNow], {opacity:100}); this.aNav[this.iNow].className="active"; }, next : function(){ this.iNow++; this.iNow==this.aImg.length&&(this.iNow=0); this.turnImgs(); },};function fade (obj, json){ clearInterval(obj.fadeTimer); obj.fadeTimer = setInterval(function(){ for(var attr in json){ var iCur=0; iCur=parseInt(parseFloat(getStyle(obj, attr))*100); var iSpeed=(json[attr]-iCur)/20; iSpeed=iSpeed>0?Math.ceil(iSpeed):Math.floor(iSpeed); if(attr=="opacity"){obj.style.opacity=(iCur+iSpeed)/100;} obj.style.filter="alpha(opacity:"+(iCur+iSpeed)+")"; } },30);}window.onload=function(){ var oBanner=getByClass(document.body, "banner")[0]; var aImg=getByClass(document.body, "imgs")[0].getElementsByTagName("li"); var aNav=getByClass(document.body, "nav")[0].getElementsByTagName("li"); var b1=new Banner({ banner: oBanner, //容器 img: aImg, //图片 nav: aNav, //按钮导航 speed: 5000 //切换速度 });};</script>
0 0
- 封装的焦点轮播图代码
- jQuer焦点图--带缩略图的焦点图幻灯代码
- ScaleHeight 的封装代码
- 管道代码的封装
- jquery的代码封装
- 功能代码的封装
- [javascript] 封装一个实用的焦点图切换效果【转】
- 焦点轮播图的制作
- Jquery焦点图插件的HTML代码
- 最简短的js焦点图代码
- 自动切换焦点的代码实现
- 焦点轮播图代码详解!基础版本
- 原生JS实现焦点轮播图 完整代码
- 封装我的VBA代码
- 关于代码架构的封装
- 选择文件夹代码的封装
- 触发器内的代码封装
- php 分页代码的封装
- iOS-沙盒机制-整合篇
- mysql如何处理auto_increment
- 芯片启动过程 ARM C51 Soc - RTOS LINUX - 之一
- CardView的学习
- iOS9 新特新介绍
- 封装的焦点轮播图代码
- mysql主从复制学习分享
- java基础的界面美化
- OpenPortal Wifi认证、Portal协议认证、WEB认证解决方案
- JSON利用superobject进行资料交换及重新封装ClientDataSet
- Java学习基础
- MFC操作SQL数据库的类
- [Matlab]未能加载文件或程序集“xx”或它的某一个依赖项。生成此程序集的运行时比当前加载的运行时新,无法加载此程序集。 Source: mscorlib HelpLink
- 常见技术名词整理(2)