优势:基于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. SQL语句优化 学习笔记

    sql语句时间花在哪了? 1 等待时间 2 执行时间 这两个时间并非孤立的,单条语句执行的快 其他语句等待的时间就少 执行时间花在哪了? 1 查找 沿着索引查找 慢者可能全表扫描 2 取出 查到行后, ...

  2. css的样式问题

    项目里面遇到一个布局: 然后侧边栏菜单的高度要随着内容的高度变化而变化:所以在这里贴一下代码:效果如下 <!DOCTYPE html> <html lang="en&quo ...

  3. zabbix监控之同时向多人邮件报警

    安装环境:  zabbix-server zabbix邮件报警配置步骤说明: 安装发送邮件的工具sendEmail 准备一个发送邮件的脚本 修改zabbix配置文件中指定的脚本路径 关联脚本名称 用户 ...

  4. python接口测试中—Requests模块的使用

    Requests模块的使用 中文文档API:http://2.python-requests.org/en/master/ 1.发送get.post请求 import requests reponse ...

  5. 牛顿迭代法——C语言

    include <stdio.h> include <math.h> int main() { flaot solution(float a,flaot b,float c,f ...

  6. Python核心技术与实战——十五|深入了解迭代器和生成器

    我们在前面应该写过类似的代码 for i in [1,2,3,4,5]: print(i) for in 语句看起来很直观,很便于理解,比起C++或Java早起的 ; i<n;i++) prin ...

  7. Java并发编程实战 第13章 显式锁

    接口Lock的实现类: ReentrantLock, ReentrantReadWriteLock.ReadLock, ReentrantReadWriteLock.WriteLock Reentra ...

  8. mapper映射文件配置之select、resultMap(转载)

    原文地址:http://www.cnblogs.com/dongying/p/4073259.html 先看select的配置吧: <select         <!-- 1. id ( ...

  9. 重置grafana密码

    [root@host~]# sqlite3 /var/lib/grafana/grafana.db SQLite version 3.7.17 2013-05-20 00:56:22 Enter &q ...

  10. linux 最大文件打开数

    配置文件 vim /etc/security/limits.conf   # /etc/security/limits.conf##This file sets the resource limits ...