好久没写博客了,变得好懒呀,无地自容。最近一直在学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. CSS: Table-Layout & Word-Break 设置表和列的宽度固定不变

    1. 设置Table的列宽由表格宽度和列宽度设定(指定表格宽度,各个列宽度): table#tbl_id{table-layout:fixed;} 2. 设置TD内容根据宽度进行换行,即使字符串之间无 ...

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

    目前Azure针对虚拟机提供两种类型的存储,一种是标准存储,基于HDD的,一种是高性能存储Premium Storage(在下文中简称PS),基于SSD的.针对用户高性能,低延迟,I/O密集型的应用, ...

  3. FATAL:NO bootable medium found!System halted.

    问题描述:致命错误,没有可引导的媒体.系统挂起.以下是在网上查的: 1:检查硬盘的类型,ide或sata接口是否在0,0或是在1,0. 2:光驱是否选择iso文件. 3:iso文件是否损坏4:virt ...

  4. c++ 10

    一.二叉树 1.基本特征 1)树型结构的最简模型,每个节点最多有两个子节点--左子节点和右子节点. 2)单根性,每个子节点有且仅有一个父节点,整棵树有且仅有一个根节点. 3)递归性,以任何一个节点为根 ...

  5. DELL WIN7系统安装 U盘

    1.老毛挑制作U盘启动安装  http://www.laomaotao.net/ 2.下载WIN7 COPY里面的内容到U盘根目录,然后将bootmgr文件更名为win7mgr 3.开进F2修改BIO ...

  6. 烟雾检测笔记1--《Video-based smoke detection with histogram sequence of LBP and LBPV pyramids》解析、实现

    基于HEP(histograms of equivalent patterns[1])框架下的特征具有良好的纹理分类效果,LBP(local binary patterns[2])属于HEP框架下最常 ...

  7. 【HDU1162】Eddy's picture(MST基础题)

    很基础的点坐标MST,一不留神就AC了, - - !! #include <iostream> #include <cstring> #include <cstdlib& ...

  8. Install Cocos2d-x v3.3 on Ubuntu 14.04 & Ubuntu 14.10(转)

    Install Cocos2d-x v3.3 on Ubuntu 14.04 & Ubuntu 14.10 1 get the source code sudo apt-get install ...

  9. .NET 中使用 HttpWebResponse 时 Cookie 的读取

    今天把一个网站登录配置到以前写的蜘蛛程序中,发现不能成功登录.检查后才发现,那个网站在登录成功后,输出了一个特殊路径的 Cookie,由于是使用 HttpWebRequest.Cookies 来获取的 ...

  10. RESTEasy 3.X Helloworld

    最近呢,RESTEasy也升级了.升到了3.X. 官网:http://www.jboss.org/resteasy 集成使用也非常简单(相比SOAP而言) 第一步:下载jar包 resteasy是托管 ...