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">&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)

时间: 2024-08-03 15:42:06

jq轮播图插件的相关文章

Javascript知识汇总------手写jq轮播图插件(2018-04-23 17:16)

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" con

自已动手写的轮播图插件,功能不断增加中,可以下载

前,平时总是使用别人的轮播图插件,这次决定自已写一个,功能越多越好.实际现起来,发现并不容易.先实现基本的功能,下两周要丰富起来. 图是别人的图,心是自已的心.直接上代码: 一:结构 <!-- carousel begin --><div class="carousel-wrap">    <div class="carousel-main-wrap">        <ul class="carousel-scr

10个免费的响应式jQuery Carousel 轮播图插件

jQuery Carousel 轮播图插件可以给网站创建华丽的动画效果,这里列出的10个jQuery Carousel 轮播图插件都是响应式的,并且可以免费使用. 1. ItemSlide.js 简单的触摸式Carousel 轮播图插件,提供多种样式的旋转动画,如向上滑动,基于全屏的触摸滑动,左右滑动等. 2. Liquid 每当Liquid 容器的大小改变时,都会重新调整列表中的项目数,以适应新的宽度. 3. jCarousel jCarousel 是一个用来控制水平或垂直方向上列表项的jQu

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

SuperSlide 2  轮播图插件,较老.但还好用. 适用于PC,是绑定到jquery上的方法: $.slide(); 如果在实际中找不到.slide方法,请检查jquery等.js文件的引入次序.(另外切忌不要引入两次jquery.js,会把$的方法洗掉而导致失效的) http://www.superslide2.com/ 官网 http://www.superslide2.com/SuperSlide.2.1.2/jquery.SuperSlide.2.1.2.js jquery.Sup

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

Bootstrap JS插件使用 > 对于Bootstrap的JS插件,我们只需要将文档实例中的代码粘到我们自己的代码中> 然后作出相应的样式调整 Bootstrap中轮播图插件叫作Carousel 一.基本的轮播图实现 HTML代码 1 <!-- 2 以下容器就是整个轮播图组件的整体, 3 注意该盒子必须加上 class="carousel slide" data-ride="carousel" 表示当前是一个轮播图 4 bootstrap.js

如何用面向对象的思维去封装一个小型轮播图插件

1.面向对象与面向过程 既然说到面向对象的思维,那就免不了要对面向过程的编程思维与面向对象的思维做一番比较. 笔者有 一段时间天真的认为有一个类,然后new一个对象就是面向对象编程了,现在想想还是太naive了呀. 其实面向对象的编程思维和面向过程的编程思维重要的不是对象和过程,而是思维. 比如说在生活中我们要做一道西红柿炒鸡蛋,很多人的第一反应就是西红柿炒鸡蛋第一步.第二步.第三步应该怎么做,每一步放什么调料.然后在做的过程中找每一步需要的调料.这就是很典型的面向过程的思维方式:怎么做,需要什

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

轮播图实现的效果为,鼠标移入左右箭头会出现,可以点击切换图片,下面的小圆点会跟随,可以循环播放.本篇文章的主要目的是分享封装插件的思路. 轮播图的我一开始是写成非插件形式实现的效果,后来才改成了封装成插件的形式. 首先要明白轮播图的实现原理和基本布局,大概就是外面有一个容器包裹着(通常是div),容器设置宽高,以及overflow为hidden,超出宽高部分隐藏, 容器里面又包含着另一个容器,包裹着所有的图片,宽为所有图片的总宽度,ul的position为absolute,通过改变ul的left

基于js的自适应、多样式轮播图插件(兼容IE8+、FF、chrome等主流浏览器)

插件github地址:https://github.com/pomelott/slider-plug_in 使用方式: slider plug-in 左右滑动的自适应.多样式全能插件.多次调用时只需传入最外层盒子ID即可. 1.根据html中的Dom结构引入图片. 2.引入css和js文件 3.调用pomeloSlider.doslide(obj) sliderwidth:轮播图宽度,单位为像素,默认自适应全屏. outer:最外层盒子ID,默认为"outer" time:轮播的时间间

Html5添加Tabs样式单页多图轮播图插件教程

一.HTML结构 <div id="slideBox"> <div class="J_slide"> <!-- 轮播图 --> <div class="J_slide_clip"> <ul class="J_slide_list"> <li class="J_slide_item"> <a href="javascrip