好久没写博客了,变得好懒呀,无地自容。最近一直在学sass和jq插件的写法,照猫画虎的谢了一个jq的插件,也算是第一次真正称得上插件的插件 ,废话不多说 上代码

(function($) {   

    $.fn.carousel = function(options) {
if($(this).length==)return false;
var opts = $.extend({},$.fn.carousel.defaults,options);
function Slide(o){
this.o = o;
this.box = o.find(opts['imgbox']);
this.cirEle = this.box.find(opts['cirEle'])
this.nav = o.find(opts['slideNav']);
this.rightAr = o.find(opts['rightAr']);
this.leftAr = o.find(opts['leftAr']);
this.et = opts['eventType'];
this.autoPlay = opts['autoPlay'];
this.navClass = opts['navClass'];
this.speed = opts['speed']
this.timer = null;
this.len = this.cirEle.length;
this.cirNavEle = null;
this.onOff = true;
this.activeIndex = ;
this.iNow = ;
this.boxWidth = this.box.outerWidth() } Slide.prototype.init = function(){
var _this = this;
_this.createNav().togglePage();
this.leftAr.on('click',function(){
_this.play(); })
this.rightAr.on('click',function(){
_this.play();
}) if(this.autoPlay){
this.stop();
this.timer = setInterval(function(){
_this.play();
},this.speed[]); this.o.hover(function(){
_this.stop();
},function(){
_this.timer = setInterval(function(){
_this.play();
},_this.speed[])
}) }
}
Slide.prototype.createNav = function(){
var _this = this;
var arr = [];
$.each(_this.cirEle,function(i,n){
if(i == ){
arr.push('<span class="cur">'+ (i+) +'</span>');
}else{
arr.push('<span>'+ (i+) +'</span>');
_this.cirEle.eq(i).css({'left':_this.boxWidth});
} }); _this.nav.html(arr.join(''));
this.cirNavEle = _this.nav.find('span');
return this; }
Slide.prototype.togglePage = function(){
var _this = this;
this.cirNavEle.on(_this.et,function(){
if(_this.onOff){
_this.onOff = false; _this.activeIndex = $(this).index(); $(this).addClass(_this.navClass).siblings().removeClass(_this.navClass); if(_this.activeIndex > _this.iNow){
_this.toggleRight(); }else if( _this.activeIndex < _this.iNow ){
_this.toggleLeft();
}
_this.cirEle.eq(_this.activeIndex).animate({'left':},_this.speed[],function(){
_this.onOff = true;
$(this).css({'z-index':}).siblings().css({'z-index':})
}) _this.iNow = _this.activeIndex;
}
}) return this; }
Slide.prototype.toggleLeft= function(){
var _this = this;
_this.cirEle.eq(_this.activeIndex).css({'left':-_this.boxWidth})
_this.cirEle.eq(_this.iNow).animate({'left':_this.boxWidth},_this.speed[])
}
Slide.prototype.toggleRight= function(){
var _this = this;
_this.cirEle.eq(_this.activeIndex).css({'left':_this.boxWidth})
_this.cirEle.eq(_this.iNow).animate({'left':-_this.boxWidth},_this.speed[])
} Slide.prototype.play = function(dir){
var _this = this;
if(_this.onOff){
_this.onOff = false;
if(!dir){
_this.activeIndex++;
_this.activeIndex %= _this.len;
_this.toggleRight(); }else{
_this.activeIndex--;
if(_this.activeIndex <= ){
_this.activeIndex = ;
}
_this.toggleLeft(); } _this.cirEle.eq(_this.activeIndex).animate({'left':},_this.speed[],function(){
_this.onOff = true;
_this.iNow = _this.activeIndex;
_this.cirNavEle.eq(_this.activeIndex).addClass(_this.navClass).siblings().removeClass(_this.navClass);
$(this).css({'z-index':}).siblings().css({'z-index':})
}) } }
Slide.prototype.stop = function(){
clearInterval(this.timer);
} return this.each(function () {
var $this = $(this);
var obj = new Slide($this);
obj.init();
}); }; //默认配置
$.fn.carousel.defaults = {
'imgbox' : '.carousel-box', //滚动元素父容器
'cirEle' : 'li', //滚动元素
'slideNav' : '.carousel-nav', //图片索引菜单
'autoPlay' : true, //是否自动轮播
'rightAr' : '.arR', //下一张
'leftAr' : '.arL', //上一张
'speed':[,], //速度 一张显示出来的时间, 间隔时间
'eventType' : 'click', //切换方式
'navClass' : 'cur' //当前菜单高亮css }
})(jQuery);

HTML

<div class="area">
<div class="carousel-box">
<ul>
<li><a href="#1"><img src="data:images/1.jpg" alt=""></a></li>
<li><a href="#2"><img src="data:images/2.jpg" alt=""></a></li>
<li><a href="#3"><img src="data:images/3.jpg" alt=""></a></li>
<li><a href="#4"><img src="data:images/4.jpg" alt=""></a></li>
<li><a href="#5"><img src="data:images/5.jpg" alt=""></a></li>
<li><a href="#6"><img src="data:images/6.jpg" alt=""></a></li>
<li><a href="#7"><img src="data:images/7.jpg" alt=""></a></li>
</ul>
</div>
<div class="carousel-nav"></div>
<span class="arL">&lt;</span>
<span class="arR">&gt;</span> </div>
<script>
$(function(){
$('.area').carousel();
})
</script>

css

.area, .area .carousel-box {
width: 310px; } .area .carousel-nav span, .area .arR, .area .arL {
width: 20px;
height: 20px;
border: 1px solid #666;
text-align: center;
display: inline-block; } .area .carousel-box ul, .area .carousel-box li {
position: absolute;
left:;
top:; } .area {
margin: 50px auto; }
.area .carousel-box {
height: 350px;
overflow: hidden;
position: relative; }
.area .carousel-nav span.cur {
background: #000;
color: #FFF; }
.area .arR, .area .arL {
margin-top: 20px; }
 

现在回头想想,其实jq插件并不是想象的那么的难,难的还是在实现功能的思路上,写法和平常js也都差不多,上面现在只是简单的实现左右轮播,有时间把上下方向也加上,嘎嘎

jq插件处女座 图片轮播的更多相关文章

  1. html+jq实现简单的图片轮播

    今天上班没事,就自己琢磨着写一下图片轮播,可是没想到,哈哈竟然写出来啦,下面就贴出来代码,作为纪念保存下下哈: <body style="text-align: center;&quo ...

  2. jQuery插件slider实现图片轮播

    1:引入相应的js文件  jquery.SuperSilder.js 2:HTML: 结构 注:此地加载图片的代码也可以从后台库中读取图片的集合列表,然后通过循环的方式显示出来 3:CSS 样式定义左 ...

  3. 原生JS实现"旋转木马"效果的图片轮播插件

    一.写在最前面 最近都忙一些杂七杂八的事情,复习软考.研读经典...好像都好久没写过博客了... 我自己写过三个图片轮播,一个是简单的原生JS实现的,没有什么动画效果的,一个是结合JQuery实现的, ...

  4. PgwSlideshow-基于Jquery的图片轮播插件

    0 PgwSlideshow简介 PgwSlideshow是一款基于Jquery的图片轮播插件,基本布局分为上下结构,上方为大图轮播区域,用户可自定义图片轮播切换的间隔时间,也可以通过单击左右方向按键 ...

  5. 12款经典的白富美型—jquery图片轮播插件—前端开发必备

    图片轮播是网站中的常用功能,用于在有限的网页空间内展示一组产品图片或者照片,同时还有非常吸引人的动画效果.本文向大家推荐12款实用的 jQuery 图片轮播效果插件,帮助你在你的项目中加入一些效果精美 ...

  6. Nivo Slider - 世界上最棒的 jQuery 图片轮播插件

    Nivo Slider 号称世界上最棒的图片轮播插件,有独立的 jQuery 插件和 WordPress 插件两个版本.目前下载量已经突破 1,800,000 次!jQuery 独立版本的插件主要有如 ...

  7. 图片轮播插件-carouFredSel

    carouFredSel图片轮播插件基于Jquery,比较常规的轮播插件,支持滚轮及键盘左右按键,加入其它插件可实现更加复杂的特效. 主页地址:http://caroufredsel.dev7stud ...

  8. jq实现图片轮播:圆形焦点+左右控制+自动轮播

    来源:http://www.ido321.com/862.html html代码: 1: <!DOCTYPE html> 2: <html lang="en"&g ...

  9. JQuery插件之图片轮播插件–slideBox

    来源:http://www.ido321.com/852.html 今天偶然发现了一个比较好用的图片轮播插件—slideBox 先看看效果:http://slidebox.sinaapp.com/ 代 ...

随机推荐

  1. python列表sort方法的两个参数key, reverse

    使用列表的sort方法可以进行排序,其中有两个参数用来表示排序的方式,代码: In [7]: a = ['x11','abc323','e26','112ddd'] In [8]: a.sort(ke ...

  2. 数值运算内建函数(core python programming 2nd edition 5.6.2)

    数值运算内建函数 函数  功能 abs(num) 返回 num 的绝对值 coerce(num1, num2) 将num1和num2转换为同一类型,然后以一个元组的形式返回. divmod(num1, ...

  3. jquery 做出专业的界面,SHOW 一下最近的成果~~~

    最近在项目中把整个UI框架重新做了一下,都是用Jquery实现的,没有使用EXT.EasyUI那一类的UI框架再也不用担心版权问题啦~~~~~~ 接下来我会在博客中把常用的功能分享出来,先上一下动态T ...

  4. 利用Azure高级存储搭建高性能Linux服务器(2)

    我们首先来测试随机写的IOPS,可以看到随机写的IOPS可以达到,顺序写的IOPS可以达到: $ sudo fio -filename=/data/testfile -direct=1 -iodept ...

  5. 分治算法求乘方a^b 取余p(divide and conquer)

    传统的计算方法为循环n个a相乘.时间复杂度为O(n). 如用分治算法,效率可提升至O(lgn). 结合recursive有 double pow(int a, int n){ ) ; ) return ...

  6. Android手机配置gcc,实现手机编译代码

    1.下载gcc.zip 2.把gcc.zip解压存放在/data目录下(也可以是其他目录,看个人习惯) 3.配置gcc环境变量 export GCCHOME=/data/gcc (gcc存放路径) e ...

  7. 简单的使用php多线程抓取网页

    PHP 利用 Curl Functions 可以完成各种传送文件操作,比如模拟浏览器发送GET,POST请求等等,受限于php语言本身不支持多线程,所以开发爬虫程序效率并不高,这时候往往需 要借助Cu ...

  8. Using ROWNUM in Oracle

    ROWNUM is an Oracle pseudo column which numbers the rows in a result set. SELECT rownum, table_nameF ...

  9. LeetCode_Recover Binary Search Tree

    Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing ...

  10. java设计模式--行为型模式--模板方法

    什么是模板方法,这个有待考虑,看下面: 模板方法 概述 定义一个操作中的算法的骨架,而将一些步骤延迟到子类中. TemplateMethod使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步 ...