jq轮播图插件
/*
* 使用说明
*
* 1:需要提供一个标签
* 2:lis:图片的个数
* 3:轮播图的大小 width ,height
* 4:图片的地址imgs[0].carouselImg[0] 这是本人的地址,
$('#mainCarousel').jdCarousel({lis:7,width:800,height:340,
imgSrc:[
imgs[0].carouselImg[0],
imgs[0].carouselImg[1],
imgs[0].carouselImg[2],
imgs[0].carouselImg[3],
imgs[0].carouselImg[4],
imgs[0].carouselImg[5],
imgs[0].carouselImg[6]
]
});
*/
(function($){
$.fn.extend({
jdCarousel:function(options){
//ul
var obj = $(this);
$(this).append('<ul></ul>')
for(var i=0 ; i<options.lis ; i++){
$(this).children('ul').append('<li><a href="#"><img/></a><
}
//设置样式
$(this).css({'overflow':'hidden','position':'relative'});
$(this).children('ul').css({'width':options.width,'height':options.height,'overflow':'hidden',padding:0,'position':'relative'});
$(this).find('li').css({'width':options.width,'height':options.height,'overflow':'hidden',padding:0,'position':'absolute'});
$(this).find('li img').css({'width':options.width,'height':options.height,'overflow':'hidden'})
//获得图片
$(this).find('li').each(function(index,ele){
$(this).find('img').attr('src',options.imgSrc[index]);
//设置第一张图片显示
if(index!=0){
$(this).hide();
}
});
//底部点点
$(this).append('<div class="carouselDot"></div>');
for(var i=0 ; i<options.lis ; i++){
$(this).children('.carouselDot').append('<span></span>');
}
$(this).children('.carouselDot').css({'position':'absolute','z-index':10,'bottom':20,
'left':(options.width - (options.lis*24 -8))/2 ,'background-color':'hsla(0,0%,100%,.3)',
'padding':'1px 8px',height:20,'width':options.lis*24 +5,'border-radius':'12px'});
$(this).children('.carouselDot').find('span').css({
'margin':0,'display':'inline-block','height':'12px','width':'12px','margin-right':12,'background':'white',
'border-radius':'50%'});
$(this).children('.carouselDot').find('span').eq(options.lis - 1).css('margin-right',0);
$(this).children('.carouselDot').children('span').eq(0).css('background','red');
//上下张
$(this).append('<span class="jdLeftPrev jdPNClick"><</span>');
$(this).append('<span class="jdRightNext jdPNClick">></span>');
$(this).children('.jdPNClick').css({
'display':'block','width':35,'height':50,'background':'rgba(0,0,0,0.5)','z-index':100,'position':'absolute',
'text-align':'center','line-height':'50px','top':(options.height - 25)/2,'color':'white','font-size':30
});
$(this).children('.jdRightNext').css('right',0);
$(this).children('.jdLeftPrev').css('left',0);
//轮播图运动
var last = 0;
var index = 0;
function doMove(){
obj.find('li').eq(last).hide();
obj.children('.carouselDot').children('span').eq(last).css('background','white');
obj.find('li').eq(index).show();
obj.children('.carouselDot').children('span').eq(index).css('background','red');
last = index;
index++;
if(index == options.lis){
index = 0;
}
}
var timer = null ;
timer = setInterval(doMove,1000);
//点点
// 鼠标移入事件
obj.children('.carouselDot').hover(function(){
obj.children('.carouselDot').css('cursor','pointer');
clearInterval(timer);
},function(){
timer = setInterval(doMove,1000);
});
obj.children('.carouselDot').on('mouseover','span',function(event){
// index+=1
// index = index>=options.lis?0:index;
$(this).siblings().css('background','white');
index = $(this).index();
doMove();
});
//prev next 事件
$(this).hover(function(){
$(this).children('.jdPNClick').css('background-color','rgba(0,0,0,0.5)');
},function(){
$(this).children('.jdPNClick').css('background-color','rgba(0,0,0,0.2)');
});
$(this).children('.jdPNClick').hover(function(){
clearInterval(timer);
},function(){
timer = setInterval(doMove,1000);
});
$(this).children('.jdLeftPrev').click(jdLeftPrev);
function jdLeftPrev(){
clearInterval(timer);
last = index;
index -= 1;
index = index<0? options.lis-1:index;
obj.children('.carouselDot').children('span').eq(index).siblings().css('background','white');
obj.find('li').eq(last).hide();
obj.children('.carouselDot').children('span').eq(last).css('background','white');
obj.find('li').eq(index).show();
obj.children('.carouselDot').children('span').eq(index).css('background','red');
}
$(this).children('.jdRightNext').click(jdRightNext);
function jdRightNext(){
last = index;
index += 1;
index = index==options.lis? 0:index;
obj.find('li').eq(last).hide();
obj.children('.carouselDot').children('span').eq(index).siblings().css('background','white');
obj.children('.carouselDot').children('span').eq(last).css('background','white');
obj.find('li').eq(index).show();
obj.children('.carouselDot').children('span').eq(index).css('background','red');
}
}
})
})(jQuery)
jq轮播图插件的更多相关文章
- jq轮播图插件—手写
<!DOCTYPE html><html lang="en"> <head> <meta charset="UTF-8" ...
- 学习笔记: js插件 —— SuperSlide 2 (轮播图插件,PC用)
SuperSlide 2 轮播图插件,较老.但还好用. 适用于PC,是绑定到jquery上的方法: $.slide(); 如果在实际中找不到.slide方法,请检查jquery等.js文件的引入次序 ...
- 封装一个简单的原生js焦点轮播图插件
轮播图实现的效果为,鼠标移入左右箭头会出现,可以点击切换图片,下面的小圆点会跟随,可以循环播放(为了方便理解,没有补2张图做无缝轮播).本篇文章的主要目的是分享封装插件的思路. 轮播图我一开始是写成非 ...
- jquery的fadeTo方法的淡入淡出轮播图插件
由于对基于jquery的简单插件开发有了一定的了解,慢慢的也对基于jquery的插件开发有了兴趣,在上班结束之后就研究各种插件的思路逻辑.最近开发了一款基于jquery的fadeTo方法的轮播图插件, ...
- 第124天:移动web端-Bootstrap轮播图插件使用
Bootstrap JS插件使用 > 对于Bootstrap的JS插件,我们只需要将文档实例中的代码粘到我们自己的代码中> 然后作出相应的样式调整 Bootstrap中轮播图插件叫作Car ...
- Vue轮播图插件---Vue-Awesome-Swiper
轮播图插件 Vue-Awesome-Swiper 地址:https://github.com/surmon-china/vue-awesome-swiper 安装:npm install vue-aw ...
- 原生JavaScript(js)手把手教你写轮播图插件(banner)
---恢复内容开始--- 1.轮播图插件 1.什么是插件: 为已有的程序增加功能 2.插件的特点(为什么要做成一个插件)与注意事项: 1.通用性,可移植性强 2.兼容性:不会对其他代码产生影响 3.创 ...
- vue轮播图插件之vue-awesome-swiper
移动端轮播图插件,在使用iview图形界面插件中的carousel组件无法实现触摸滑动后,转而使用vue-awesome-swiper插件 1.npm安装 npm i vue-awesome-swip ...
- js 原生轮播图插件
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
随机推荐
- eclipse下进行spark开发(已实践)
开发准备: jdk1.8.45 spark-2.0.0-bin-hadoop2.7(windows下和linux个留一份) Linux系统(centos或其它) spark安装环境 hadoop-2. ...
- AlloyTouch之select选择插件
原文地址:https://github.com/AlloyTeam/AlloyTouch/wiki/Simple-Select 写在前面 很多情况下,产品希望统一安卓和IOS select交互和样式. ...
- 《HelloGitHub月刊》第11期
<HelloGitHub>第11期 兴趣是最好的老师,<HelloGitHub>就是帮你找到兴趣! 简介 最开始我只是想把自己在浏览 GitHub 过程中,发现的有意思.高质量 ...
- 读书笔记 effective c++ Item 24 如果函数的所有参数都需要类型转换,将其声明成非成员函数
1. 将需要隐式类型转换的函数声明为成员函数会出现问题 使类支持隐式转换是一个坏的想法.当然也有例外的情况,最常见的一个例子就是数值类型.举个例子,如果你设计一个表示有理数的类,允许从整型到有理数的隐 ...
- 打造“黑客“手机--Kali Nethunter
从三月份开始,继续更新技术文章.一个月没有更新技术文章了,这一个月有一部分时间是在休息,另一部分时间是在学习汇编和操作系统,沉淀底层和逆向方面的技术. 今年年初,为了玩一下 kali NetHunte ...
- 关于 myBatis 中的 jdbcType的细节问题
前几天上线了一个 版本,第二天到公司的时候,在cat上发现了一个长sql查询非常耗时,几乎把线上的项目搞崩溃了.我马上开始排查问题.最终发现 球队的ID传过来的时候是String 类型的,但是在执行s ...
- JS判断手机当前的系统类型
<script language="javascript"> window.onload = function () { var n = navigator.userA ...
- MySQL学习分享-->查询-->查询的原理
查询的原理 在一个查询中常包含下述子句: 1.select,2.distinct,3.join,4.on,5.from,6.where,7.having,8.group by,9.order by,1 ...
- Xamarin自定义布局系列——瀑布流布局
Xamarin.Forms以Xamarin.Android和Xamarin.iOS等为基础,自己实现了一整套比较完整的UI框架,包含了绝大多数常用的控件,如下图 虽然XF(Xamarin.Forms简 ...
- 1741: [Usaco2005 nov]Asteroids 穿越小行星群
1741: [Usaco2005 nov]Asteroids 穿越小行星群 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 231 Solved: 166 ...