实战编写jq插件轮播图
2017-01-11 10:10
309 查看
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <style> *{padding: 0px;margin: 0px;list-style: none;border: none;vertical-align: middle;} .utl li img{float: left;} .utl{width: 2800px;height: 250px;position: absolute;left: 0;top: 0;} .umhext{overflow: hidden;width: 700px;height:250px;margin: 50px auto; position: relative;} .bordernone{position: absolute;bottom: 10px;left: 50%;} .bordernone i{border: 2px solid #000000;width: 15px;height: 15px;display: inline-block;border-radius: 50%;cursor: pointer;z-index: 1;margin-left: 5px;} .bordernone i.auctiy{ border: 2px solid red; } </style> <script src="http://code.jquery.com/jquery-2.0.0.js"></script> <body> <div class="umhext"> <ul class="utl"> <li><img src="1.png"/></li> <li><img src="2.png"/></li> <li><img src="1.png"/></li> <li><img src="2.png"/></li> </ul> <span class="bordernone"></span> </div> <script> (function($){ // 初始化数据 var CarouselRest = { auctiy:"auctiy", //标签 iI:"<i></i>", //标签 i:"i", //类 utl:".utl", //标签 bordernone:".bordernone", //标签 timer:1000, //时间 widthUmhext:700, //img宽度 widthUtl:2800, //总宽度 widthBordernone:80, //iI总宽度 height:250, //img高度 findLi:"li", //标签 Fn:"Function", //是否为函数 fag:true //是否开启定时器true开启 false关闭 } // 建立数据对象 $.fn.Carousel = function(pm){ // 如果参数就重新赋值否则就是默认 var options = $.extend(true, CarouselRest, pm); var _self = $(this); //初始化索引 var index = 0; return _self.each(function(){ var len = _self.find(CarouselRest.findLi); //计算出所有的小圆圈 for (var i = 0 ; i<len.length ; i++) { _self.find(CarouselRest.bordernone).append(CarouselRest.iI); } _self.find(CarouselRest.i).eq(0).addClass(CarouselRest.auctiy); //小圆圈居中 _self.find(CarouselRest.bordernone).css({ "left":"50%", "marginLeft":-CarouselRest.widthBordernone/2 }) //小圆圈事件操作 _self.find(CarouselRest.i).on("click",function(){ index = $(this).index(); view(index); }) //图片自动事件 function auto(){ index++; if(index>=len.length){ index = 0; } view(index); } //在次进行封装 function view(index){ _self.find(CarouselRest.i).eq(index).addClass(CarouselRest.auctiy) .siblings(CarouselRest.i) .removeClass(CarouselRest.auctiy); _self.find(CarouselRest.utl).stop().animate({ left:-CarouselRest.widthUmhext*index },230) } //开启定时器 var stop=null if(CarouselRest.fag){ stop = setInterval(auto,CarouselRest.timer); _self.hover(function(){ clearTimeout(stop) },function(){ stop = setInterval(auto,CarouselRest.timer); }) } }) } })(jQuery) $(".umhext").Carousel({ auctiy:"auctiy", //类 iI:"<i></i>", //标签 i:"i", //类 utl:".utl", //标签 bordernone:".bordernone", //类 timer:1500, //时间 widthUmhext:700, //img宽度 widthUtl:2800, //总宽度 widthBordernone:80, //iI总宽度 height:250, //img高度 findLi:"li", //标签 Fn:"Function", //是否为函数 fag:true //是否开启定时器true开启 false关闭 }); </script> </body> </html>
相关文章推荐
- jq编写轮播插件
- 基于jq的图片轮播插件,滑动切图,兼容移动,PC端
- jq插件的编写方法(自定义jq插件)
- jq 插件编写 待
- jQ 编写插件
- 编写Gradle插件配合ASM框架实战
- [jq] 最终确定的jq插件结构编写
- Bootstrap轮播(carousel)插件中图片变形的终极解决方案——使用jqthumb.js
- jq插件轮播unslider2.03版用法
- jq封装淘宝图片轮播插件
- jQ插件编写
- 个人学习JQ插件编写成果:little酷炫的图片滑动切换效果
- JQ 图片轮播插件,可设置方向和效果。
- 如何编写jquery插件之轮播图
- jq自定义插件—$.fn的使用之(轮播图)兼容性都ok
- 【前端】jq插件的编写
- 【maven实战】46-编写Maven插件
- 用jQuery编写轮播图插件
- Bootstrap轮播插件中图片变形的终极解决方案 使用jqthumb.js
- JS+JQ轮播图插件