今天做工作的时候,轻车熟路的做完,又用到了bootstrap的轮播图,觉得有必要安利一下这个插件,如果你需要的轮播图。功能不需要太炫酷,那么bootstrap的插件是你的首要选择。

使用方式

引入js和css

直接引入bootsrap.js和bootstrap.css两个文件即可。

示例html代码


<div id="myCarousel" class="carousel slide"> <!-- 轮播(Carousel)指标 --> <ol class="carousel-indicators"> <li data-target="#myCarousel" data-slide-to="0" class="active"></li> <li data-target="#myCarousel" data-slide-to="1"></li> <li data-target="#myCarousel" data-slide-to="2"></li> </ol> <!-- 轮播(Carousel)项目 --> <div class="carousel-inner"> <div class="item active"> <img src="/wp-content/uploads/2014/07/slide1.png" alt="First slide"> <div class="carousel-caption">标题 1</div> </div> <div class="item"> <img src="/wp-content/uploads/2014/07/slide2.png" alt="Second slide"> <div class="carousel-caption">标题 2</div> </div> <div class="item"> <img src="/wp-content/uploads/2014/07/slide3.png" alt="Third slide"> <div class="carousel-caption">标题 3</div> </div> </div> <!-- 轮播(Carousel)导航 --> <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev"> <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span> <span class="sr-only">Previous</span> </a> <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next"> <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> <span class="sr-only">Next</span> </a> </div>

上面的示例代码从菜鸟教程直接copy过来的。根据需要酌情删减。

js初始化

$('.carousel').carousel()

carousel里面有一些选项,可以进行设置。

interval:轮播的间隔时间,默认值5000

pause:何时暂停,默认值hover,鼠标悬浮上去,则暂停。值改为null,意味着无论怎样都不暂停。

wrap:轮播是否连环,默认为true。

keyboard:是否相应键盘操作,默认为true。

一些方法事件

//轮播事件为200
$('#identifier').carousel({
interval: 2000
})
//从左到右循环轮播 $('#identifier').carousel('cycle')
//停止轮播
$('#identifier').carousel('pause')
//轮播到某一帧 $('#identifier').carousel(0)
$('#identifier').carousel(1)
//轮播到上一个项目 $('#identifier').carousel('prev')
//轮播到下一个项目 $('#identifier').carousel('next')

回调函数

//滑动时出发的回调

$('#identifier').on('slide.bs.carousel', function () {
// 执行一些动作...
}) //完成滑动过渡效果后,触发的事件 $('#identifier').on('slid.bs.carousel', function () {
// 执行一些动作...
})

自己使用例子

搞一个点击哪里,跳转哪里的东西

var car = $(".carousel");
car.carousel('pause');
$("#firstLi").bind("click", function() {
car.carousel(0);
car.carousel('pause');
}); $("#secondLi").bind("click", function() {
car.carousel(1);
car.carousel('pause');
});

有什么好处

先说一下swiper插件,他确实好用,功能强大,但是不支持ie8。支持ie8的版本swiper2不支持自动调整高度的功能。

owl-carousel支持自动调整高度,支持ie8.但是他在ie8下会有个闪烁的问题,这个官网也存在此问题,是个bug。

最终bootstrap的轮播图最为好使。

聊一聊 bootstrap 的轮播图插件的更多相关文章

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

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

  2. Bootstrap中轮播图

    Bootstrap中轮播图插件叫作Carousel,为了清晰的表明每个标签在这里是什么意思,我把解释写在了下面的代码中. <!-- 以下容器就是整个轮播图组件的整体, 注意该盒子必须加上 cla ...

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

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

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

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

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

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

  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. 20182320《Program Design and Data Structures》Learning Summary Week9

    20182320<Program Design and Data Structures>Learning Summary Week9 1.Summary of Textbook's Con ...

  2. Linux中ps -elf和ps aux的区别

    一.前言 Linux下输入命令man ps查看: 加横线是 standard syntax   -- 比如ps -elf  不加横线是 BSD syntax   -- 比如ps aux To see ...

  3. 13. Go 语言网络爬虫

    Go 语言网络爬虫 本章将完整地展示一个应用程序的设计.编写和简单试用的全过程,从而把前面讲到的所有 Go 知识贯穿起来.在这个过程中,加深对这些知识的记忆和理解,以及再次说明怎样把它们用到实处.由本 ...

  4. verilog常见错误列表

    Error/Warning 来源:https://hdlbits.01xz.net/wiki/ 题目: 1.Quartus Warning 10235: Warning (): Verilog HDL ...

  5. 体感在js中的调用

    体感技术,在于人们可以很直接地使用肢体动作,与周边的装置或环境互动,而无需使用任何复杂的控制设备,便可让人们身临其境地与内容做互动. 体感分为三大类: 惯性感测:主要是以惯性传感器为主,例如用重力传感 ...

  6. 前端之HTML介绍及使用

    一.HTML介绍 1.1 web本质 在pycharm写入一下代码,然后在浏览器地址栏输入地址和端口127.0.0.1:8080,回车,回来运行代码,直接访问客户端发送的内容conn.send(b'& ...

  7. 深入selenium模块基础操作

    selenium模块的基本操作 一.模拟浏览器 ​ 谷歌.Firefox.Safari等浏览器 browser=webdriver.Chrome() browser=webdriver.Firefox ...

  8. java版本的Kafka消息写入与读取

    安装zookeeper:  https://www.cnblogs.com/guoyansi19900907/p/9954864.html 并启动zookeeper 安装kafka https://w ...

  9. CICD-Jenkins笔记2014-2018

    CICD-Jenkins笔记2014-2018 20141119 chenxin 20180726 chenxin update 四个环境,开发/测试/预发布/生产. 文中涉及的最新脚本,请查看西部战 ...

  10. Saltstack_使用指南15_多master

    1. 主机规划 实现2个master,当这两个master运行时都可以向minion发送命令. salt 版本 [root@salt100 ~]# salt --version salt (Oxyge ...