Bootstrap 轮播
描述
このチュートリアルでは、Bootstrap を使用してカルーセルを作成する方法を説明します。これにより、コンテンツスライダー、画像ギャラリーなどを作成できます。
用法
<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="../index.html" data-slide="prev">‹</a> <a class="carousel-control right" href="../index.html" data-slide="next">›</a> </div>
したがって、表示したい項目(たとえば images)を循環順に "carousel-inner" div 内に配置し、"<!-- Carousel nav -->" を使用して項目のナビゲーションを作成します。カスタム data 属性 "data-slide" を使用して、前後の項目にナビゲーションします。
カルーセルを作成したいHTMLファイルで、jquery.jsとbootstrap-carousel.jsファイルを参照する必要があります。
Bootstrapカルーセルの例
实例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bootstrap の next と previous 付きページネーションの例</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.html" rel="stylesheet">
<style type="text/css">
body {
margin: 50px;
}
</style>
</head>
<body>
<ul class="pager">
<li>
<a href="../index.html">Previous</a>
</li>
<li>
<a href="../index.html">Next</a>
</li>
</ul>
</body>
</html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bootstrap の next と previous 付きページネーションの例</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.html" rel="stylesheet">
<style type="text/css">
body {
margin: 50px;
}
</style>
</head>
<body>
<ul class="pager">
<li>
<a href="../index.html">Previous</a>
</li>
<li>
<a href="../index.html">Next</a>
</li>
</ul>
</body>
</html>
オンラインでサンプルを見る
oldとnewを使用したページ送りの例
实例
<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="../index.html"><img src="../images/w3r.png.html" width="111" height="30" alt="w3resource logo" /></a>
<div class="nav-collapse">
<ul class="nav">
<li class="active"><a href="../index.html">Home</a></li>
<li><a href="../index.html">About</a></li>
<li><a href="../index.html">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.html" alt="HTML5 logo" width="500" height="99" /></div>
<div class="item"><img src="../update-images/javascript-logo.png.html" alt="JS logo" width="500" height="99" /></div>
<div class="item"><img src="../update-images/schema.png.html" alt="Schema.org logo" width="500" height="99" /></div>
<div class="item"><img src="../update-images/json.gif.html" alt="JSON logo" width="500" height="99" /></div>
</div>
<!-- Carousel nav -->
<a class="carousel-control left" href="../index.html" data-slide="prev">‹</a>
<a class="carousel-control right" href="../index.html" data-slide="next">›</a>
</div>
</div>
</div>
<hr>
<footer>
<p>© Company 2012</p>
</footer>
</div> <!-- /container -->
<!-- Le javascript
================================================== -->
<!-- ドキュメントのページ下部に配置して読み込み速度を速めます -->
<script src="twitter-bootstrap-v2/docs/assets/js/jquery.js.html"></script>
<script src="twitter-bootstrap-v2/docs/assets/js/bootstrap-carousel.js.html"></script>
<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="../index.html"><img src="../images/w3r.png.html" width="111" height="30" alt="w3resource logo" /></a>
<div class="nav-collapse">
<ul class="nav">
<li class="active"><a href="../index.html">Home</a></li>
<li><a href="../index.html">About</a></li>
<li><a href="../index.html">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.html" alt="HTML5 logo" width="500" height="99" /></div>
<div class="item"><img src="../update-images/javascript-logo.png.html" alt="JS logo" width="500" height="99" /></div>
<div class="item"><img src="../update-images/schema.png.html" alt="Schema.org logo" width="500" height="99" /></div>
<div class="item"><img src="../update-images/json.gif.html" alt="JSON logo" width="500" height="99" /></div>
</div>
<!-- Carousel nav -->
<a class="carousel-control left" href="../index.html" data-slide="prev">‹</a>
<a class="carousel-control right" href="../index.html" data-slide="next">›</a>
</div>
</div>
</div>
<hr>
<footer>
<p>© Company 2012</p>
</footer>
</div> <!-- /container -->
<!-- Le javascript
================================================== -->
<!-- ドキュメントのページ下部に配置して読み込み速度を速めます -->
<script src="twitter-bootstrap-v2/docs/assets/js/jquery.js.html"></script>
<script src="twitter-bootstrap-v2/docs/assets/js/bootstrap-carousel.js.html"></script>
オンラインでサンプルを見る
使用 Javascript
以下の JavaScript コードを使用してカルーセルを作成できます。
$('.carousel').carousel()
以下は、使用できるものです。选项
- interval: スライドの切り替えの待機時間をミリ秒単位で指定します。値の型は number で、デフォルト値は 5000 です。false の場合、カルーセルは自動的に循環を開始しません。
- pause: マウスがスライド領域に留まっている間はカルーセルを一時停止し、マウスが離れるとカルーセルを再開します。値の型は string で、デフォルト値は 'hover' です。
以下は、使用できるカルーセルです。方法
- .carousel(options): カルーセルコンポーネントを初期化し、オプションの object 型の options パラメータを受け取り、スライドの循環を開始します。
$('.carousel').carousel({
interval: 2000 // in milliseconds
})
$('.carousel').carousel('cycle');
$('#myCarousel').hover(function () {
$(this).carousel('pause')
}
$("#carousel_nav").click(function(){
var item = 4;
$('#home_carousel').carousel(item);
return false;
});
ここに二つあります事件カルーセルの機能を強化するために使用されます。
- slide: slide インスタンスメソッドが呼び出された後、このイベントが直ちにトリガーされます。
- slid: すべてのスライドの再生が完了すると、このイベントがトリガーされます。
ここをクリックして、本チュートリアルで使用するすべてのHTML、CSS、JSおよび画像ファイルをダウンロードしてください。
其他扩展