/*
 * 使用说明 
 *   
 *   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">&lt;</span>');
$(this).append('<span class="jdRightNext jdPNClick">&gt;</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轮播图插件的更多相关文章

  1. jq轮播图插件—手写

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

  2. 学习笔记: js插件 —— SuperSlide 2 (轮播图插件,PC用)

    SuperSlide 2  轮播图插件,较老.但还好用. 适用于PC,是绑定到jquery上的方法: $.slide(); 如果在实际中找不到.slide方法,请检查jquery等.js文件的引入次序 ...

  3. 封装一个简单的原生js焦点轮播图插件

    轮播图实现的效果为,鼠标移入左右箭头会出现,可以点击切换图片,下面的小圆点会跟随,可以循环播放(为了方便理解,没有补2张图做无缝轮播).本篇文章的主要目的是分享封装插件的思路. 轮播图我一开始是写成非 ...

  4. jquery的fadeTo方法的淡入淡出轮播图插件

    由于对基于jquery的简单插件开发有了一定的了解,慢慢的也对基于jquery的插件开发有了兴趣,在上班结束之后就研究各种插件的思路逻辑.最近开发了一款基于jquery的fadeTo方法的轮播图插件, ...

  5. 第124天:移动web端-Bootstrap轮播图插件使用

    Bootstrap JS插件使用 > 对于Bootstrap的JS插件,我们只需要将文档实例中的代码粘到我们自己的代码中> 然后作出相应的样式调整 Bootstrap中轮播图插件叫作Car ...

  6. Vue轮播图插件---Vue-Awesome-Swiper

    轮播图插件 Vue-Awesome-Swiper 地址:https://github.com/surmon-china/vue-awesome-swiper 安装:npm install vue-aw ...

  7. 原生JavaScript(js)手把手教你写轮播图插件(banner)

    ---恢复内容开始--- 1.轮播图插件 1.什么是插件: 为已有的程序增加功能 2.插件的特点(为什么要做成一个插件)与注意事项: 1.通用性,可移植性强 2.兼容性:不会对其他代码产生影响 3.创 ...

  8. vue轮播图插件之vue-awesome-swiper

    移动端轮播图插件,在使用iview图形界面插件中的carousel组件无法实现触摸滑动后,转而使用vue-awesome-swiper插件 1.npm安装 npm i vue-awesome-swip ...

  9. js 原生轮播图插件

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

随机推荐

  1. (C#)xml的简单理解创建和读取

    xml知识点清理:一.文档规则 1.区分大小写. 2.属性值必须加引号(单引号.双引号都可以),一般情况下建议使用使用双引号. 3.所有标记必须有结束符号. 4.所有空标记必须关闭. 5.必须有且仅有 ...

  2. 在vim中,使用可视化拷贝(剪切)粘贴文本

    1  定位光标到你想要开始剪切的位置 2 按v选择字符(按V是选择整行) 3 移动光标到你想要结束剪切的位置 4 按d是为了剪切(按y是为了拷贝) 5 移动光标到你想要粘贴的位置 6 按P是在光标之前 ...

  3. 自己动手搭建苹果推送Push服务器

    今天我们来说下怎么自己建一个Push推送服务器, 当然还是用的苹果的APNS 这里我们讲的的自己服务器端的实现 在做推送服务器之前我们要先做一些准备动作 #1. 确保你的App ID有启用PushNo ...

  4. devexpress显示缓冲滚动条与实现类似QQ消息推送效果

    1.一般在项目中处理大数据,或者查询大量数据时,耗时会很长,这个时候缓冲条是必不可少的.这里展示一个devexpress不错的缓冲条,如图所示: 使用到了控件splashScreenManager,运 ...

  5. 做一款直播类app

    ijkplayer 是一款做视频直播的框架, 基于ffmpeg, 支持 Android 和 iOS, 网上也有很多集成说明, 但是个人觉得还是不够详细, 在这里详细的讲一下在 iOS 中如何集成ijk ...

  6. Excel与XML相互转换 - C# 简单实现方案

    Excel与XML相互转换 - C# 简单实现方案 在日常工作中,我需要将数据存储在Excel中进行数据分析和处理,然后再将数据转换为XML格式进行跨平台的数据交换.网上搜索Excel转换为XML的实 ...

  7. HttpWebRequest 模拟网站登录获取数据

    此文档仅仅是一个BaseCode,已做后续查阅 项目使用IBM Platform Symphony分布式平台,所有业务处理都在这个分布式平台上计算,需求是获取这些计算机机群的运行状态,和每一个服务的的 ...

  8. Spring Cache扩展:注解失效时间+主动刷新缓存

    *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...

  9. 网络服务器系统wamp的安装

    第一步,下载wamp Server 可以百度查找下载,也可以到WAMP的官方网站http://wampserver.com/en下载,官网下载会比较慢. 第二步,下载之后,双击运行,安装 第三步,解压 ...

  10. Debian/Ubuntu安装Oracle客户端TNS

    本文作为新手在Linux上部署Java程序的必经之路的Oracle客户端配置,请高手绕道. 确定服务器版本 首选确定你的Oracle服务器版本,以便下载相应的客户端.查看的sql如下: select ...