图片轮播这种效果在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. Velocity原理

    1.准备 添加引用:velocity-1.7.jar,velocity-tools-2.0.jar,commons-beanutils-1.7.0.jar,commons-chain-1.1.jar, ...

  2. Jquery入门之----------选择器-------------

    Jquery最核心的组成部分就是选择器引擎.他继承了CSS的语法,可以对DOM元素的标签名.属性名.状态等进行快速.精确的选择,并且不必担心浏览器的兼容性.Jquery选择器除实现了基本的标签选择外, ...

  3. Linux shell实现Mysql异地备份数据库

    #--------------------------Mysqldump异地备份-----------------# #!/bin/bash #start mysqldump back /usr/bi ...

  4. Linux安装VritualBox实现虚拟机win2003端口映射 支持远程

    1. 使用VNC登录到Linux系统 2. 安装VritualBox 找到VritualBox的软件包 这里的是run格式的 可以直接在终端运行  需要几分钟时间 3.VritualBox新建虚拟机 ...

  5. IOS屏幕布局

    1.iPad和iPhone的屏幕布局 在IB中,屏幕或控件的尺寸以点为单位.在视网膜技术中,1个点包括4个像素,而没有采用视网膜屏幕技术的还是1个点包括1个像素. 2.绝对布局和相对布局 3.使用Au ...

  6. sqoop导入数据到hive

    1.1hive-import参数 使用--hive-import就可以将数据导入到hive中,但是下面这个命令执行后会报错,报错信息如下: sqoop import --connect jdbc:my ...

  7. C#代码利用MongoDB中Group聚合函数查询

    例子: public static void getUserRFM(DateTime beginTime, DateTime endTime)        {            MongoDat ...

  8. ThinkPHP之中的getField、Find、select、返回数据类型详解(ThinkPHP之中所有数据读取了)

    小李子:用于演示作用的数据库表:customers 官方解读: “ 读取数据集其实就是获取数据表中的多行记录(以及关联数据),使用select方法 ” $customers=D('customers' ...

  9. 在 Windows 7 環境安裝 Python 2.6.6

    目前 Python 的最穩定的版本是 2.7.3 及 3.2.3,因為 2.x 與 3.x 語法並不是完全相容,在各版本之間也有些差異,所以建議還是各自安裝需要的版本… 艾小克工作環境是使用 2.6 ...

  10. javascript中split字符串分割函数

    1. var ss=s.split("fs"); for(var i=0;i<ss.length;i++){ 处理每一个ss[i]; } 2. "2:3:4:5&q ...