优势:基于es5,兼容高。切换动画css配置,轻量,不包含多余代码,可扩展性很高,多个轮播图不会冲突,可配置独有namespace

注:

1、项目需要所写,所以只写了页码的切换,未写上一页下一页按钮,不过js里面包含下一页代码,只需要config扩展一个切换上一页下一页按钮的class,照猫画虎写一个上一页的方法即可

2、提供了可配置当前激活项得class,默认active,这样可以根据项目需要进行配置,不至于限制死(一个页面多个轮播,即使全用active也没问题,因为内部做了space)

3、namespace只有new Swiper时候传入一个即可 内部使用任何相同的class都没问题

4、页码、轮播只能使用li(想要修改可以自己修改源码find(li)换成其余的)

下面放下swiper的源码:

var Swiper = function(bannerContine){
this._loopTime = 3000;
this._currentImgNum = 0;
this._currentClass = "active";
this._imgListLength = 0;
this._bannerContine = bannerContine;
this._timer = null;
this._config = null;
this._pageContine = null;
this.setImgNumber = function(index){
this._currentImgNum = index
}
// 设置index
this.setNextImgNumber = function(){
if(this._currentImgNum == this._imgListLength - 1){
this.setImgNumber(0);
}else{
this.setImgNumber(this._currentImgNum + 1);
}
}
// 翻页到指定number
this.gotoImgByNum = function(index){
this.setImgNumber(index);
$(this._bannerContine).find("li").removeClass(this._currentClass)
.eq(index).addClass(this._currentClass);
if(this._pageContine){
$(this._pageContine).find("li").removeClass(this._currentClass)
.eq(index).addClass(this._currentClass);
}
}
// 下一页
this.next = function(){
this.setNextImgNumber();
this.gotoImgByNum(this._currentImgNum);
}
// 开始轮播
this.autoPlay = function(){
var that = this;
if(this._timer){
clearTimeout(this._timer);
}
this._timer = setTimeout(function(){
that.next();
that.autoPlay();
},that._loopTime)
}
// 重置轮播时间
this.suspendPlay = function(){
if(this._config.autoPlay && this._config.autoPlay.toString() == "true"){
clearTimeout(this._timer);
var that = this;
setTimeout(function(){
that.autoPlay();
},0)
}
}
this.stopPlay = function(){
clearTimeout(this._timer);
}
// 启动器
this.run = function(config){
var that = this;
this._imgListLength = $(this._namespace + " " + this._bannerContine).find("li").length;
this._config = config;
if(config.currentClass){
this._currentClass = config.currentClass.toString();
}
if(config.startNum !== "" && config.startNum !== null && config.startNum !== undefined){
this._currentImgNum = parseInt(config.startNum);
}
if(config.pageContine && config.pageContine != ""){
this._pageContine = config.pageContine;
$(this._pageContine).find("li").each(function(index){
$(this).on("click",function(e){
e.stopPropagation();
that.gotoImgByNum(index);
that.suspendPlay();
})
})
}
this.gotoImgByNum(this._currentImgNum);
if(config.delayTime){
this._loopTime = parseInt(config.loopTime);
}
if(config.autoPlay && config.autoPlay.toString() == "true"){
this.autoPlay();
} }
}

使用方法:

html:

<div class='cms_banner_container'>
<ul class="banner_container_imgul">
<li>
<img src="https://preview.qiantucdn.com/58pic/28/60/74/52s58PICnbu97bbKkf6te_PIC2018.jpg!w1024_new_small" alt="">
</li>
<li>
<img src="https://preview.qiantucdn.com/58pic/27/89/84/75058PICta44WaKcE2PNY_PIC2018.png!w1024_new_0" alt="">
</li>
<li>
<img src="https://preview.qiantucdn.com/58pic/28/08/69/43y58PICrzW58PICr85358PIC58PICm658PIC_PIC2018.png!w1024_new_0" alt="">
</li>
<li>
<img src="https://preview.qiantucdn.com/58pic/17/79/16/93358PIC9Av71d6Xwe7cc_PIC2018.jpg!w1024_new_small" alt="">
</li>
</ul>
<ul class = "banner_pagination banner_pagination0">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
</div>

css:

* {
margin:;
padding:;
list-style: none;
} .cms_banner_container{
width:100%;
height:100%;
position: relative;;
}
/*
图片列表的样式
*/
.banner_container_imgul{
position: relative;
width:100%;
height:100%;
}
.banner_container_imgul li {
position: absolute;
top:;
height:;
width:100%;
height:100%;
opacity:;
transition:all 1.5s ease-in-out 0s; /* 常用的简写方式 */
}
.banner_container_imgul li.active{
opacity:;
} .banner_container_imgul li img{
width:100%;
height:100%
}
/*
页码的样式
*/
.banner_pagination {
position: absolute;
z-index:;
bottom:30px;
left:50%;
transform: translateX(-50%);
}
.banner_pagination li {
display: inline-block;
width:20px;
height:20px;
line-height: 20px;
text-align: center;
background:#000;
border-radius: 50%;
color:#fff;
cursor: pointer;
}
.banner_pagination li.active{
background:#fff;
color:#000;
}

js

  window.onload = function(){
// 传入一个节点的class或者id
var swiper = new Swiper(".banner_container_imgul");
// 执行run 传入config
/**
* config参数大全
* @param {Boolean} autoPlay 是否开启自动循环 默认false 不开启不会注册loop函数
* @param {Number} loopTime 自动循环时间 默认3000
* @param {Number} startNum 起始图片
* @param {String} currentClass 标记当前index的class(默认 active)注:会同时激活img li和page li
* @param {String} pageContine 页码节点的class 如果不传不会注册页码的点击事件
*/ swiper.run({
autoPlay:true,
loopTime:3000,
pageContine:".banner_pagination",
})
}

这是一个完整的轮播图,懒的同学可以直接拷贝,亲测写多个,兼容完全没问题  放心用就好啦

jquery版本轮播图(es5版本,兼容高)的更多相关文章

  1. mobile_轮播图_transform 版本_transform 读写二合一

    轮播图_transform 版本 关键点: 2D 变换 transform 不会改变 元素 在 文档流 中的位置 定位 position 会改变 元素 在 文档流 中的位置 语句解析太快,使用 set ...

  2. 用js和jQuery做轮播图

    Javascript或jQuery做轮播图 css样式 <style> a{ text-decoration:none; } .naver{ width: 100%; position:r ...

  3. 用jQuery实现轮播图效果,js中的排他思想

    ---恢复内容开始--- jQuery实现轮播图不用单独加载. 思路: a. 通过$("#id名");选择需要的一类标签,获得一个伪数组 b.由于是伪数组的原因,而对数组的处理最多 ...

  4. mobile_轮播图_style_left 版本

    mobile 轮播图 小圆点逻辑(排他) 1. 统一给所有 span 元素加 class=""; 2. 切换到谁,谁的 class="active"; 移动端轮 ...

  5. 自实现PC端jQuery版轮播图

    最近其他项目不是很忙,被安排给公司的官网项目做一个新的页面(之前没接触公司官网项目),其中有一个用到轮播图的地方,最开始想直接用swiper.js插件实现就好了,可是发现官网项目里之前都没有引入过sw ...

  6. JQuery实现轮播图及其原理

    源码: <!DOCTYPE html> <html> <head> <meta charset="utf-8" name="vi ...

  7. Jquery无缝轮播图的制作

    轮播是html页面中比较常见的一种展现形式,也是基础,把轮播图做好,是排版中比较关键的 1.首先是轮播的html元素放置:做轮播之前,要有一个初步的认识 2.每个元素的位置怎样摆放,也是很关键的,这里 ...

  8. jquery优化轮播图2

    继续优化 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...

  9. jquery改造轮播图1

    g改造轮播图1:https://www.cnblogs.com/huanghuali/p/8677338.html <!DOCTYPE html> <html lang=" ...

随机推荐

  1. sqlserver2008 批量导出所有的作业

    SQl server 代理 -- 选中作业 -- 按 F7,弹出 对象资源管理详细信息 ,里面对作业多选以后右键就有导出 sql的菜单了

  2. vue video.js使用

    插件github地址:https://github.com/videojs/video.js 这边做一个切换视频vue url的解决记录 this.$nextTick(() => { let u ...

  3. 2019-11-29-git无法pull仓库refusing-to-merge-unrelated-histories

    title author date CreateTime categories git无法pull仓库refusing to merge unrelated histories lindexi 201 ...

  4. linux格式化磁盘命令

    linux格式化磁盘命令           linux mkfs         指令:mkfs 使用权限 : 超级使用者 使用方式 : mkfs [-V] [-t fstype] [fs-opti ...

  5. 电脑系统win7和samba服务器连接不上解决办法

    1.修改本地安全策略运行secpol.msc打开“本地安全策略”窗体,依次点开“本地策略”->“安全选项”,修改“网络安全: LAN 管理器身份验证级别”的值为“发送 LM 和 NTLM – 如 ...

  6. 魔术矩阵Java代码

    //该魔术矩阵默认从右上角45度递增 //@漫流——595128841在qq点com //import java.util.Arrays; //用于打印API函数 public class 魔方矩阵 ...

  7. PAT Advanced 1050 String Subtraction (20 分)

    Given two strings S​1​​ and S​2​​, S=S​1​​−S​2​​ is defined to be the remaining string after taking ...

  8. scrapy 知乎关键字爬虫spider代码

    以下是spider部分的代码.爬知乎是需要登录的,建议使用cookie就可以了,如果需要爬的数量预计不多,请不要使用过大的线程数量,否则会过快的被封杀,需要等十几个小时账号才能重新使用,比起损失的这十 ...

  9. canvas 计算文字宽度(常用于文字换行)

    var c=document.getElementById("myCanvas"); var ctx=c.getContext("2d"); ctx.font= ...

  10. keep-alive 组件级缓存

    前言 在Vue构建的单页面应用(SPA)中,路由模块一般使用vue-router.vue-router不保存被切换组件的状态, 它进行push或者replace时,旧组件会被销毁,而新组件会被新建,走 ...