image.png
<div id="myCarousel" class="carousel slide"> <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> <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> <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>
手动调用轮播:$('.carousel').carousel()
参数设置
image.png
方法
设置循环:
('#identifier').carousel('cycle') 停止轮播: $('#identifier').carousel('pause')
轮播到特定:
('#identifier').carousel('prev')
(function(){ // 初始化轮播
("#myCarousel").carousel('cycle'); }); // 停止轮播
("#myCarousel").carousel('pause'); }); // 循环轮播到上一个项目
("#myCarousel").carousel('prev'); }); // 循环轮播到下一个项目
("#myCarousel").carousel('next'); }); // 循环轮播到某个特定的帧
("#myCarousel").carousel(0); });
("#myCarousel").carousel(1); });
("#myCarousel").carousel(2); }); }); </script>
事件
slide.bs.carousel
('#identifier').on('slid.bs.carousel', function () { // 执行一些动作... })