Bootstrap-carousel-plugin
提供:Dev Guides
ブートストラップ-カルーセルプラグイン
Bootstrapカルーセルは、サイトにスライダーを追加するための柔軟で応答性の高い方法です。 レスポンシブであることに加えて、コンテンツは、画像、iframe、ビデオ、または必要に応じてあらゆる種類のコンテンツを許可するのに十分な柔軟性を備えています。
'_このプラグイン機能を個別に含める場合は、 carousel.js が必要です。 または、リンク:/bootstrap/bootstrap_plugins_overview [Bootstrap Plugins Overview]で説明されているように、_bootstrap.js_または縮小された_bootstrap.min.js_を含めることができます。_
例
以下の簡単なスライドショーは、Bootstrapカルーセルプラグインを使用して、カルーセルのような要素を循環するための一般的なコンポーネントを示しています。 カルーセルを実装するには、マークアップ付きのコードを追加するだけです。 データ属性の必要はなく、単純なクラスベースの開発が必要です。
オプションのキャプション
使用法
- データ属性経由-データ属性を使用して、カルーセルの位置を簡単に制御します。
- 属性 data-slide は、キーワード_prev_または_next_を受け入れます。これらは、現在の位置に関連してスライドの位置を変更します。
- data-slide-to を使用して、生のスライドインデックスをカルーセル data-slide-to = "2" に渡します。これにより、スライド位置が0で始まる特定のインデックスに移動します。
- data-ride = "carousel" 属性を使用して、ページの読み込み時にカルーセルをアニメーションとしてマークします。
- Via JavaScript -以下のようにJavaScriptを使用してカルーセルを手動で呼び出すことができます-
オプション
データ属性またはJavaScriptを介して渡すことができる特定のオプションがありますが、次の表にリストされています-
Option Name | Type/Default Value | Data attribute name | Description |
---|---|---|---|
interval | number Default − 5000 | data-interval | The amount of time to delay between automatically cycling an item. If false, carousel will not automatically cycle. |
pause | string Default − "hover" | data-pause | Pauses the cycling of the carousel on mouseenter and resumes the cycling of the carousel on mouseleave. |
wrap | boolean Default − true | data-wrap | Whether the carousel should cycle continuously or have hard stops. |
方法
カルーセルコードで使用できる便利なメソッドのリストを次に示します。
Method | Description | Example |
---|---|---|
.carousel(options) | Initializes the carousel with an optional options object and starts cycling through items. | |
.carousel('cycle') | Cycles through the carousel items from left to right. | |
.carousel('pause') | Stops the carousel from cycling through items. | |
.carousel(number) | Cycles the carousel to a particular frame (0 based, similar to an array). | |
.carousel('prev') | Cycles to the previous item. | |
.carousel('next') | Cycles to the next item. |
例
次の例は、メソッドの使用法を示しています-
イベント
ブートストラップのカルーセルクラスは、次の表に示すカルーセル機能にフックするための2つのイベントを公開します。
Event | Description | Example |
---|---|---|
slide.bs.carousel | This event fires immediately when the slide instance method is invoked. | |
slid.bs.carousel | This event is fired when the carousel has completed its slide transition. |
例
次の例は、イベントの使用法を示しています-