jquery版本轮播图(es5版本,兼容高)
优势:基于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版本,兼容高)的更多相关文章
- mobile_轮播图_transform 版本_transform 读写二合一
轮播图_transform 版本 关键点: 2D 变换 transform 不会改变 元素 在 文档流 中的位置 定位 position 会改变 元素 在 文档流 中的位置 语句解析太快,使用 set ...
- 用js和jQuery做轮播图
Javascript或jQuery做轮播图 css样式 <style> a{ text-decoration:none; } .naver{ width: 100%; position:r ...
- 用jQuery实现轮播图效果,js中的排他思想
---恢复内容开始--- jQuery实现轮播图不用单独加载. 思路: a. 通过$("#id名");选择需要的一类标签,获得一个伪数组 b.由于是伪数组的原因,而对数组的处理最多 ...
- mobile_轮播图_style_left 版本
mobile 轮播图 小圆点逻辑(排他) 1. 统一给所有 span 元素加 class=""; 2. 切换到谁,谁的 class="active"; 移动端轮 ...
- 自实现PC端jQuery版轮播图
最近其他项目不是很忙,被安排给公司的官网项目做一个新的页面(之前没接触公司官网项目),其中有一个用到轮播图的地方,最开始想直接用swiper.js插件实现就好了,可是发现官网项目里之前都没有引入过sw ...
- JQuery实现轮播图及其原理
源码: <!DOCTYPE html> <html> <head> <meta charset="utf-8" name="vi ...
- Jquery无缝轮播图的制作
轮播是html页面中比较常见的一种展现形式,也是基础,把轮播图做好,是排版中比较关键的 1.首先是轮播的html元素放置:做轮播之前,要有一个初步的认识 2.每个元素的位置怎样摆放,也是很关键的,这里 ...
- jquery优化轮播图2
继续优化 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...
- jquery改造轮播图1
g改造轮播图1:https://www.cnblogs.com/huanghuali/p/8677338.html <!DOCTYPE html> <html lang=" ...
随机推荐
- React中构造函数constractor,为什么要用super(props)
前言 昨天晚上公司组织了前端分享会,在讲到React Class方法的时候,有的同学提出,为什么构造函数一定要super,我记得我之前看的黑马视频里面有讲过,就再翻出来 内容 React官方中文文档里 ...
- install-info - 更新 info/dir 项
SYNOPSIS 总览 install-info [OPTION]... [INFO-FILE [DIR-FILE]] DESCRIPTION 描述 从 Info 目录文件 DIR-FILE 中的文件 ...
- error: (-215) !empty() in function detectMultiScale
tips: pip install opencv-python or https://www.lfd.uci.edu/~gohlke/pythonlibs/ 原因确实是找不到 opencv 的 xml ...
- pandas库
pandas是基于NumPy数组构建的,特别是基于数组的函数和不使用for循环的数据处理.虽然pandas采用了大量的NumPy编码风格,但二者最大的不同是pandas是专门为处理表格和混杂数据设计的 ...
- 索尼展示基于MicroLED技术的16K显示屏:约780吋
尽管 8K 彩电刚刚在消费级市场崭露头角,更极致的 16K 却已不慌不忙地登场了. 在日前于拉斯维加斯举办的 NAB 2019 展会上,索尼就秀出了旗下的 16K 显示设备,它目前正在日本横滨的资生堂 ...
- SpringMVC 中的注解@RequestParam与@PathVariable的区别
@PathVariable绑定URI模板变量值 @PathVariable是用来获得请求url中的动态参数的 @PathVariable用于将请求URL中的模板变量映射到功能处理方法的参数上.//配置 ...
- [bzoj4358]permu:莫队+线段树/回滚莫队
这道题是几天前水过去的,现在快没印象了,水一发. 首先我们看到它让求解的是最长的值域 连续段长度,很好. 然后就想到了山海经,但但是我还没有做. 然后又想到了很久以前的一次考试的T3旅馆hotel(我 ...
- N皇后问题的递归与非递归解法
都在注释里了: public class NQueen { public static void main(String[] args) { Scanner sc = new Scanner(Syst ...
- vue interceptors(拦截器)
拦截器 顾名思义: 就是半路个您劫持, 拦截器 其实在项目和自己写demo中,总会遇到请求方面需要在请求头里面做判断或者添加一些东西, 这时候 vue 中应用中axios的 interceptors ...
- mysql8.0.16二进制安装
mysql8.0.16二进制安装 环境简介操作系统:Centos 6.10 64位 目前版本:8.0.16 MySQL Community Server 二进制 安装目录:/data/mysql/my ...