图片轮播这种效果在web开发中看常见,网上的插件也有很多,最近在整理项目的过程中,把之前的图片轮播效果整合了一下,整理成一个可调用的插件以做记录,也方便更多前端爱好者来学习使用;
图片的轮播原理很简单,无非是动画改变需要运动元素的top、left等值;先来看插件的基本代码:

/**
* Created by jone on 2016/5/3.
*/
(function($){
$.fn.slider=function(options){
var defaults={
width:1000,
height:300,
autoPlay: true,
sliderArrow: true,
sliderBar: true,
speed: 3000,
effect: 'horizontal',
responsive: false ,
callback: function() {}, }
var obj = $.extend(defaults, options);
var index=0;
var timer=null; this.each(function(index, el) {
var me = $(this);
if (obj.responsive) {
var parent = me.parent();
me.css('width', parent.width())
me.children("ul").find("li").css('width', me.width())
} else {
me.css({
width: obj.width,
height: obj.height,
})
me.children("ul").find("li").css({
width: obj.width,
height: obj.height,
})
}
var li_width = me.children("ul").find("li").width();
var li_height = me.children("ul").find("li").height();
var li_length = me.children("ul").find("li").length; me.children("ul").css({
position: 'absolute',
left: 0,
top: 0,
width: li_width * li_length
})
me.children("ul").find("li").css("float","left");
if (obj.sliderArrow) {
var btn = "<span class='btn prev'><</span>" + '' + "<span class='btn next'>></span>"
me.append(btn);
me.find(".btn").hide();
me.find(".prev").click(function() {
index--;
if (index < 0) {
index = li_length - 1
}
moveIndex(index);
})
me.find(".next").click(function() {
index++;
if (index > li_length - 1) {
index = 0
} moveIndex(index); })
};
if (obj.sliderBar) {
var bar = "<em class='bar'></em>";
me.append(bar);
for (var i = 0; i < li_length; i++) {
me.find('.bar').append('<i></i>')
};
me.find('.bar i').eq(0).addClass('on');
me.find('.bar').css('marginLeft', -me.find('.bar').outerWidth() / 2);
me.find('.bar i').on("mouseenter", function() {
index = $(this).index();
moveIndex(index)
})
};
if (obj.autoPlay) {
clearInterval(timer)
timer = setInterval(autoMove, obj.speed);
} me.hover(function() {
clearInterval(timer);
me.find(".btn").fadeIn();
}, function() {
me.find(".btn").fadeOut();
if (obj.autoPlay) {
timer = setInterval(autoMove, obj.speed);
} else {
return
}
}); function autoMove() {
index++;
if (index > li_length - 1) {
index = 0
}
moveIndex(index);
}; function moveIndex(index) {
switch(obj.effect.toLowerCase()) {
case 'horizontal':
me.children("ul").stop(true, true).animate({left: -index * li_width}, 800);
me.find('.bar i').eq(index).addClass('on').siblings().removeClass('on');
break;
case 'vertical':
me.children("ul").width(li_width);
me.children("ul").find("li").css("float","none");
me.children("ul").stop(true, true).animate({top: -index * li_height}, 800);
me.find('.bar i').eq(index).addClass('on').siblings().removeClass('on');
break;
case 'fade':
me.children("ul").width(li_width);
me.children("ul").find("li").css({
float:'none',
position:'absolute',
left:0,
top:0,
});
me.children("ul").find("li").eq(index).fadeIn().siblings().fadeOut();
me.find('.bar i').eq(index).addClass('on').siblings().removeClass('on');
break;
}
}
});
}
})(jQuery)

插件的调用:

$("#slider1").slider({
effect:'fade',
width:730,
height:454
});

插件基本API:

width:1000,             // 滚动容器宽;
height:300, // 滚动容器高;
autoPlay: true, // 默认开启自动滚动;
sliderArrow: true, // 默认开启左右切换箭头;
sliderBar: true, // 默认开启分页切换栏目;
speed: 3000, // 速度;
effect: 'horizontal', // 轮播效果,默认水平,有horizontal、vertical、fade供选择;
responsive: false , // 响应式,默认不开启;
callback: function() {},// 回调函数;

直接来看DEMO吧:http://codepen.io/jonechen/pen/reQqGK

插件下载:http://files.cnblogs.com/files/jone-chen/jquery.slider.js.zip

jQuery图片无缝轮播插件;的更多相关文章

  1. jQuery图片无缝轮播

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  2. js实现图片无缝轮播

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. jQ实现图片无缝轮播

    在铺页面的过程中,总是会遇到轮播图需要处理,一般我是会用swiper来制作,但总会有哪个几个个例需要我自己来写功能,这里制作了一个jq用来实现图片无缝轮播的dome,分享给大家ヽ( ̄▽ ̄)ノ. dom ...

  4. js和jquery实现图片无缝轮播的不同写法

    多掌握一种方法总是会有好处的,学习编程就要多思考,举一反三 下面写一下实现图片自动播放的代码,由于学习的是javascript,代码量很大,所以又学习了jquery库的操作,非常简便 还有非常有逼格的 ...

  5. 基于Jquery的banner轮播插件,简单粗暴

    新手练习封装插件,觉着在前端这一块的轮播比较多,各种旋转木马一类的3D旋转,技术不够,所以封装了一个简单的banner轮播插件,功能也比较简单,就是左右向的轮播. 先挂地址https://github ...

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

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

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

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

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

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

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

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

随机推荐

  1. 008sudo用户管理

    1.Sudo是Unix/Linux平台上一个非常有用的工具,它允许系统管理员分配给普通用户一些合理的权利,让它们执行一些只有超级用户或其他特许用户才能完成的任务(主要体现为命令),比如,运行一些像mo ...

  2. 视频特效制作:如何给视频添加边框、水印、动画以及3D效果

    2014-12-08 09:47 编辑: suiling 分类:iOS开发 来源:叶孤城的blog 招聘信息: iOS手机软件开发工程师 iOS工程师 Web后端高级开发工程师 iOS软件工程师 ja ...

  3. HTML自动换行的问题

    有时文本文字已经超过所在的区域,但是文字还是不自动换行 可以用强制换行 强制不换行div{ white-space:nowrap;}自动换行div{ word-wrap:break-word; wor ...

  4. FireFox Prevent this page from creating addtional dialogs 火狐浏览器 设置 阻止此页面创建更多对话框

    FireFox英文版本老弹出“Prevent this page from creating addtional dialogs”的确认框 FireFox english version alert ...

  5. PropertyGrid 控件使用方法

    编写一个对象,后面传递给 PropertyGrid 来显示: using System; using System.Collections.Generic; using System.Linq; us ...

  6. C++基本数据类型解惑

    记得刚学C语言的时候,对那些double,float,long,unsigned int各种混乱,基本是随便用,对数据类型没有一个整体的框架.最近学习<<C++ primer plus&g ...

  7. 第十八章 数据访问(In .net4.5) 之 I/O操作

    1. 概述 本章内容包括 文件操作.流操作.读写网络数据 以及 异步I/O操作. 2. 主要内容 2.1 文件操作 ① 使用 Drive 和 DriveInfo 访问磁盘信息. DriveInfo[] ...

  8. MongoDB 学习笔记(三)—— 修改器的使用

    通常文档只会有一部分数据要更新,所以使用修改器来操作文档极为高效. 小技巧:了解函数功能,不带括号即可.如:db.blog.update即可查看update函数的具体参数和方法体. $set修改器 & ...

  9. lldb

    所有命令选择与input 值用  -- 区分 1 p/x 16 转16进制 https://sourceware.org/gdb/onlinedocs/gdb/Output-Formats.html ...

  10. EMVTag系列12《卡片内部风险管理数据》

    Ø  9F53    连续脱机交易限制数(国际-货币) L: 1 -C(有条件):如果执行国际-货币频度检查 PBOC专有数据元. 不使用指定应用货币的连续脱机交易次数最大数,超过后交易请求联机 模板 ...