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/ 代 ...
随机推荐
- PayPal 开发详解(四):买家付款
1.点击[立即付款] 2.使用[个人账户]登录paypal Personal测试帐号 3.核对商品信息 4.确认信息无误,点击[立即付款],提示付款成功,跳转到商家设置的URL 5.URL中包含pa ...
- javaSE第二十七天
第二十七天 447 1:反射(理解) 447 (1)类的加载及类加载器 447 (2)反射: 448 A:定义 448 B:获取字节码对象的三种方式 449 (3) ...
- CentOS安装中文输入法
yum install "@Chinese Support" System->Preferences->Input Method,勾选"Enable inpu ...
- 关于使用SVN update时出现:E155004错误
今天早上到公司开了电脑,准备update下SVN的代码,但是在update时出现svn: E155004: Working copy 'E:\XX' locked 错误,乍眼一看以为是什么配置出错, ...
- Custom PeopleSoft Queries
The following SQL identifies custom queries created in your system from the PSQRYDEFN PeopleTools ...
- Setup Factory 程序打包
1.检测是否已安装 在On Startup中写入如下代码: result1=Registry.DoesKeyExist(HKEY_LOCAL_MACHINE, "Software\\sohe ...
- [leetcode]_Count and Say
题目:一开始没看懂, 后头经过WA发现 输出 的意义 是 出现的次数+值. 1 => 一个1 => 11 11 => 两个1 => 21 111=> 三个1 => ...
- angularJS 数组更新时重新排序之解决方案一:这个坑,绕开吧,不跳了……
今天产品大人发现了一bug,图表数据和数据库总是对不上,原因是当前端更新数组时,angularJS默认对数组进行了排序. // 点击事件:input复选框 $scope.fnClickUpdateAr ...
- php文件hash算法,秒传原理
header('Content-type:text/html;Charset=UTF-8'); define('blockSize', 4*1024*1024); var_dump(fileHash( ...
- Nginx Location配置语法介绍、优先级说明
nginx 语法规则:location [=|~|~*|^~|!~|!~*] /uri/ { … } location匹配的是$document_uri,$document_uri 会随 ...