Bootstrap的圖片輪播示例代碼
示例一:
插入js及css支持:
<link rel="stylesheet" href="css/bootstrap.min.css"/> <script src="js/jquery-1.9.1.min.js"></script> <script src="js/bootstrap.min.js"></script>
HTML代碼:
<div id="pictures" class="item"> <div id="myCarousel" class="carousel slide"> <!-- 輪播(Carousel)指標(biāo) --> <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)項(xiàng)目 --> <div class="carousel-inner"> <div class="item active"> <img src="images/gf.jpg" class="img-responsive" alt="First slide"> </div> <div class="item"> <img src="images/psb.jpg" class="img-responsive" alt="Second slide"> </div> <div class="item"> <img src="images/uyt.jpg" class="img-responsive" alt="Third slide"> </div> </div> <!-- 輪播(Carousel)導(dǎo)航 --> <a class="carousel-control left" href="#myCarousel" data-slide="prev">‹</a> <a class="carousel-control right" href="#myCarousel" data-slide="next">›</a> </div> </div>
示例二:
用法
<div id="myCarousel" class="carousel slide"> <!-- Carousel items --> <div class="carousel-inner"> <div class="active item">…</div> <div class="item">…</div> <div class="item">…</div> </div> <!-- Carousel nav --> <a class="carousel-control left" href="#myCarousel" data-slide="prev">‹</a> <a class="carousel-control right" href="#myCarousel" data-slide="next">›</a> </div>
所以,您把想要呈現(xiàn)的條目(比如 images)以循環(huán)順序放置在 "carousel-inner" div 中,通過(guò) "<!-- Carousel nav -->" 創(chuàng)建條目的導(dǎo)航。它使用定制的 data 屬性 "data-slide" 來(lái)導(dǎo)航到上一個(gè)和下一個(gè)條目。
您必須在您要?jiǎng)?chuàng)建輪播的 HTML 文件引用 jquery.js 和 bootstrap-carousel.js 文件。
Bootstrap 輪播實(shí)例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Twitter Bootstrap pager with next and previous example</title> <meta name="description" content="Twitter Bootstrap pager with next and previous example"> <link href="/twitter-bootstrap/twitter-bootstrap-v2/docs/assets/css/bootstrap.css" rel="stylesheet"> <style type="text/css"> body { margin: 50px; } </style> </head> <body> <ul class="pager"> <li> <a href="#">Previous</a> </li> <li> <a href="#">Next</a> </li> </ul> </body> </html>
帶有 old 和 new 的翻頁(yè)實(shí)例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Example of carousal with Twitter Bootstrap</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="description" content="Example of carousal with Twitter Bootstrap version 2.0 from w3resource.com"> <!-- Le styles --> <link href="twitter-bootstrap-v2/docs/assets/css/bootstrap.css" rel="stylesheet"> <link href="twitter-bootstrap-v2/docs/assets/css/example-fixed-layout.css" rel="stylesheet"> <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements --> <!--[if lt IE 9]> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <!-- Le fav and touch icons --> <link rel="shortcut icon" href="twitter-bootstrap-v2/docs/examples/images/favicon.ico"> <link rel="apple-touch-icon" href="twitter-bootstrap-v2/docs/examples/images/apple-touch-icon.png"> <link rel="apple-touch-icon" sizes="72x72" href="twitter-bootstrap-v2/docs/examples/images/apple-touch-icon-72x72.png"> <link rel="apple-touch-icon" sizes="114x114" href="twitter-bootstrap-v2/docs/examples/images/apple-touch-icon-114x114.png"> </head> <body> <div class="navbar navbar-fixed-top"> <div class="navbar-inner"> <div class="container"> <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </a> <a class="brand" href="#"><img src="/images/w3r.png" width="111" height="30" alt="w3resource logo" /></a> <div class="nav-collapse"> <ul class="nav"> <li class="active"><a href="#">Home</a></li> <li><a href="#about">About</a></li> <li><a href="#contact">Contact</a></li> </ul> </div><!--/.nav-collapse --> </div> </div> </div> <div class="container"> <!-- Example row of columns --> <div class="row"> <div class="span4"> <h2>HTML5 and JS Apps</h2> <p> </p> <div id="myCarousel" class="carousel slide"> <!-- Carousel items --> <div class="carousel-inner"> <div class="active item"><img src="/update-images/html5_logo.png" alt="HTML5 logo" width="500" height="99" /></div> <div class="item"><img src="/update-images/javascript-logo.png" alt="JS logo" width="500" height="99" /></div> <div class="item"><img src="/update-images/schema.png" alt="Schema.org logo" width="500" height="99" /></div> <div class="item"><img src="/update-images/json.gif" alt="JSON logo" width="500" height="99" /></div> </div> <!-- Carousel nav --> <a class="carousel-control left" href="#myCarousel" data-slide="prev">‹</a> <a class="carousel-control right" href="#myCarousel" data-slide="next">›</a> </div> </div> </div> <hr> <footer> <p>© Company 2012</p> </footer> </div> <!-- /container --> <!-- Le javascript ================================================== --> <!-- Placed at the end of the document so the pages load faster --> <script src="twitter-bootstrap-v2/docs/assets/js/jquery.js"></script> <script src="twitter-bootstrap-v2/docs/assets/js/bootstrap-carousel.js"></script> </body> </html>
使用 Javascript
您可以使用下面的 JavaScript 代碼來(lái)創(chuàng)建輪播。
$('.carousel').carousel()
下面是您可以使用的選項(xiàng)
interval: 規(guī)定幻燈片輪換的等待時(shí)間,以毫秒為單位。值的類型為 number,默認(rèn)值是 5000。如果為 false,輪播將不會(huì)自動(dòng)開(kāi)始循環(huán)。
pause: 規(guī)定當(dāng)鼠標(biāo)停留在幻燈片區(qū)域即暫停輪播,鼠標(biāo)離開(kāi)即啟動(dòng)輪播。值的類型為 string,默認(rèn)值是 'hover'。
下面是您可以使用的輪播方法
.carousel(options): 初始化輪播組件,接受一個(gè)可選的 object 類型的 options 參數(shù),并開(kāi)始幻燈片循環(huán)。 $('.carousel').carousel({ interval: 2000 // in milliseconds }) .carousel('cycle'): 從左到右循環(huán)各幀。 $('.carousel').carousel('cycle'); .carousel('pause'): 停止輪播。 $('#myCarousel').hover(function () { $(this).carousel('pause') } .carousel(number): 將輪播定位到指定的幀上(幀下標(biāo)以0開(kāi)始,類似數(shù)組)。 $("#carousel_nav").click(function(){ var item = 4; $('#home_carousel').carousel(item); return false; });
.carousel('prev'): 將輪播轉(zhuǎn)到上一幀。
.carousel('next'): 將輪播轉(zhuǎn)到下一幀。
這里有兩個(gè)事件用來(lái)增強(qiáng)輪播的功能。
slide: 當(dāng) slide 實(shí)例方法被調(diào)用之后,此事件被立即觸發(fā)。
slid: 當(dāng)所有幻燈片播放完之后,此事件被觸發(fā)。
- 全面解析Bootstrap圖片輪播效果
- 全面解析Bootstrap中Carousel輪播的使用方法
- bootstrap實(shí)現(xiàn)每隔5秒自動(dòng)輪播效果
- 輕松實(shí)現(xiàn)Bootstrap圖片輪播
- BootStrap 輪播插件(carousel)支持左右手勢(shì)滑動(dòng)的方法(三種)
- Bootstrap輪播加上css3動(dòng)畫(huà),炫酷到底!
- 全面解析多種Bootstrap圖片輪播效果
- Bootstrap圖片輪播組件Carousel使用方法詳解
- Bootstrap每天必學(xué)之輪播(Carousel)插件
- bootstrap輪播模板使用方法詳解
相關(guān)文章
悄悄用腳本檢查你訪問(wèn)過(guò)哪些網(wǎng)站的代碼
YouPorn是YouTube的成人自拍版,Alexa排名61。如果你登陸YouPorn主頁(yè),它會(huì)悄悄用腳本檢查你訪問(wèn)過(guò)哪些色情網(wǎng)站。2010-12-12通過(guò)javascript實(shí)現(xiàn)掃雷游戲代碼實(shí)例
這篇文章主要介紹了通過(guò)javascript實(shí)現(xiàn)掃雷游戲代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-02-02對(duì)Web開(kāi)發(fā)中前端框架與前端類庫(kù)的一些思考
這篇文章主要介紹了對(duì)Web開(kāi)發(fā)中前端框架與前端類庫(kù)的一些思考,本文講解了前端框架的理解誤區(qū)、前端框架與前端類庫(kù)的區(qū)別、前端MVC框架思想等內(nèi)容,需要的朋友可以參考下2015-03-03微信小程序利用button控制條件標(biāo)簽的變量問(wèn)題
這篇文章主要介紹了微信小程序利用button控制條件標(biāo)簽的變量問(wèn)題,本文分步驟給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2020-03-03JavaScript實(shí)現(xiàn)猜數(shù)字游戲
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)猜數(shù)字游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-05-05