jQuery图片无缝轮播插件;
图片轮播这种效果在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图片无缝轮播插件;的更多相关文章
- jQuery图片无缝轮播
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- js实现图片无缝轮播
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- jQ实现图片无缝轮播
在铺页面的过程中,总是会遇到轮播图需要处理,一般我是会用swiper来制作,但总会有哪个几个个例需要我自己来写功能,这里制作了一个jq用来实现图片无缝轮播的dome,分享给大家ヽ( ̄▽ ̄)ノ. dom ...
- js和jquery实现图片无缝轮播的不同写法
多掌握一种方法总是会有好处的,学习编程就要多思考,举一反三 下面写一下实现图片自动播放的代码,由于学习的是javascript,代码量很大,所以又学习了jquery库的操作,非常简便 还有非常有逼格的 ...
- 基于Jquery的banner轮播插件,简单粗暴
新手练习封装插件,觉着在前端这一块的轮播比较多,各种旋转木马一类的3D旋转,技术不够,所以封装了一个简单的banner轮播插件,功能也比较简单,就是左右向的轮播. 先挂地址https://github ...
- PgwSlideshow-基于Jquery的图片轮播插件
0 PgwSlideshow简介 PgwSlideshow是一款基于Jquery的图片轮播插件,基本布局分为上下结构,上方为大图轮播区域,用户可自定义图片轮播切换的间隔时间,也可以通过单击左右方向按键 ...
- 12款经典的白富美型—jquery图片轮播插件—前端开发必备
图片轮播是网站中的常用功能,用于在有限的网页空间内展示一组产品图片或者照片,同时还有非常吸引人的动画效果.本文向大家推荐12款实用的 jQuery 图片轮播效果插件,帮助你在你的项目中加入一些效果精美 ...
- Nivo Slider - 世界上最棒的 jQuery 图片轮播插件
Nivo Slider 号称世界上最棒的图片轮播插件,有独立的 jQuery 插件和 WordPress 插件两个版本.目前下载量已经突破 1,800,000 次!jQuery 独立版本的插件主要有如 ...
- JQuery插件之图片轮播插件–slideBox
来源:http://www.ido321.com/852.html 今天偶然发现了一个比较好用的图片轮播插件—slideBox 先看看效果:http://slidebox.sinaapp.com/ 代 ...
随机推荐
- 配置DNS域名解析服务器
bind这个DNS域名解析服务器解析好后,执行下面的语句实现开启服务 named -c named.conf & -c指配置脚本named.conf的文件地址 named.conf主要有下面几 ...
- Objective-C介绍
概述 2007年苹果公司推出了Objective—C 2.0,它是Mac OS X和iOS开发的基础语言.
- Sublime Text 2 安装与使用SFTP插件
http://wbond.net/sublime_packages/sftp/usage http://www.360doc.com/content/13/0603/15/9437165_290170 ...
- Firbird 将可 null 的列更新为 not null
在GOOGLE上搜到2种方法: 第一种是新加一列 C2, 然后 update myTable set C2=原字段,再删除[原字段], 但这种方法有限制,当很多其它表引到此表时,非常麻烦. 第 ...
- PHP中英文字符串截取函数无乱码(mb_substr)和获取中英文字符串字数函数(mb_strlen)
mb_substr( $str, $start, $length, $encoding ) $str,需要截断的字符串 $start,截断开始处,起始处为0 $length,要截取的字数 $encod ...
- Generate List and Table via ng-repeat
<div ng-app ng-controller='StudentListController'> <ul> <li ng-repeat='student in stu ...
- 内存详解--理解 JVM 如何使用 AIX 上的本机内存
转自---http://www.ibm.com/developerworks/cn/java/j-nativememory-aix/
- 数组(Array),二维数组,三维数组
数组(Array):相同类型数据的集合就叫做数组. (一)定义数组的方法: A) type[] 变量名 = new type[数组中元素的个数] 例如: int[] a = new int[10] ; ...
- 禁止生成文件Thumbs.db
Thumbs.db是一个用于Microsoft Windows XP.Windows7 或 mac os x缓存Windows Explorer的缩略图的文件.Thumbs.db保存在每一个包含图片或 ...
- C#实现大数字的运算
1.添加引用:System.Numerics.dll 2.添加命名空间:using System.Numerics; 3.实例: 3.1判断一个数字是不是质数 static void Main(str ...