BootStrap轮播图官方代码:
<!--data-ride设置图片切换方式为滑动 --> <div id="carousel-example-generic" class="carousel slide" data-ride="carousel"> <!-- 设置轮播图的数量和顺序--> <!--data-target的值应与上面的id值对应 --> <ol class="carousel-indicators"> <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li> <li data-target="#carousel-example-generic" data-slide-to="1"></li> <li data-target="#carousel-example-generic" data-slide-to="2"></li> </ol> <!-- 要展示的图片信息 --> <div class="carousel-inner" role="listbox"> <div class="item active"> <img src="..." alt="..."> <div class="carousel-caption"> ... </div> </div> <div class="item"> <img src="..." alt="..."> <div class="carousel-caption"> ... </div> </div> ... </div> <!-- 控制图标 --> <a class="left carousel-control" href="#carousel-example-generic" 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="#carousel-example-generic" role="button" data-slide="next"> <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> <span class="sr-only">Next</span> </a> </div>
实现轮播图时间间隔改变的两种方式:
1、在data-ride后面加上一个属性data-interval=“millisecond”,其中,millisecond为需要设置的毫秒数,如下:
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel" data-interval="1000">
使用JavaScript语句实现:
官网给出的代码是:
$('.carousel').carousel({interval: 2000});
直接使用这个代码无法实现,应在该方法前面加上一个函数表达式,如下:
$(function(){ $('#carousel-example-generic').carousel({interval:1000});});
推荐:bootstrap入门教程