好久没写博客了,变得好懒呀,无地自容。最近一直在学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. 【笔记】Unix 平台标准

    POSIX 表示可移植操作系统接口(Portable Operating System Interface ,缩写为 POSIX ),POSIX标准定义了操作系统应该为应用程序提供的接口标准,是IEE ...

  2. 接入SDK

    管理提醒: 本帖被 fm2010 设置为精华(2014-11-12) http://www.cocoachina.com/bbs/read.php?tid-239087.html     本帖属于Co ...

  3. 畅通工程续--hdu1874

    畅通工程续 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  4. [UVA] 11991 - Easy Problem from Rujia Liu? [STL应用]

    11991 - Easy Problem from Rujia Liu? Time limit: 1.000 seconds Problem E Easy Problem from Rujia Liu ...

  5. 在VS里面查看lua堆栈

     extern std::string get_lua_stack(void); std::string stack = get_lua_stack();    std::string get_lua ...

  6. zoj 3772 Calculate the Function

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5235 这道题需要构造矩阵:F(X)=F(X-1)+F(X-2)*A(X)转化为 ...

  7. 使用Discuz!自带参数防御CC攻击以及原理,修改Discuz X 开启防CC攻击后,不影响搜索引擎收录的方法

    这部份的工作,以前花的时间太少. 希望能产生一定的作用. http://www.nigesb.com/discuz-cc-attacker-defence.html http://bbs.zb7.co ...

  8. BZOJ 2626 JZPFAR(KD-tree)

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2626 题意:平面上有n个点.现在有m次询问,每次给定一个点(px, py)和一个整数k, ...

  9. Android之SharedPreferences两个工具类

    相信Android的这个最简单的存储方式大家都很熟悉了,但是有一个小小技巧,也许你没有用过,今天就跟大家分享一下,我们可以把SharedPreferences封装在一个工具类中,当我们需要写数据和读数 ...

  10. new SqlSessionFactoryBuilder().build(inputStream, properties)

    SqlSessionFactory sqlSessionFactory =new SqlSessionFactoryBuilder().build(inputStream, properties); ...