Bootstrap JS Carousel
JS Carousel (ภาพหมุน.js)
ปลั๊กอิน Carousel เป็นส่วนประกอบสำหรับการวนผ่านองค์ประกอบต่างๆ เช่น ภาพหมุน (สไลด์โชว์)
สำหรับบทแนะนำเกี่ยวกับ Carousels โปรดอ่านBootstrap Carousel Tutorialของเรา
หมายเหตุ:ภาพหมุนไม่ได้รับการสนับสนุนอย่างถูกต้องใน Internet Explorer 9 และรุ่นก่อนหน้า (เนื่องจากใช้การเปลี่ยนภาพและภาพเคลื่อนไหว CSS3 เพื่อให้ได้เอฟเฟ็กต์สไลด์)
คลาสปลั๊กอิน Carousel
Class | Description |
---|---|
.carousel | Creates a carousel |
.slide | Adds a CSS transition and animation effect when sliding from one item to the next. Remove this class if you do not want this effect |
.carousel-indicators | Adds indicators for the carousel. These are the little dots at the bottom of each slide (which indicates how many slides there are in the carousel, and which slide the user are currently viewing) |
.carousel-inner | Adds slides to the carousel |
.icon-next | Unicode icon (arrow pointing right), used in carousels. This is often used instead of a glyphicon |
.icon-prev | Unicode icon (arrow pointing left), used in carousels. This is often used instead of a glyphicon |
.item | Specifies the content of each slide |
.left carousel-control | Adds a left button to the carousel, which allows the user to go back between the slides |
.right carousel-control | Adds a right button to the carousel, which allows the user to go forward between the slides |
.carousel-caption | Specifies a caption for the carousel |
ผ่าน data-* คุณสมบัติ
แอตทริบิวต์data-ride="carousel"
เปิดใช้งานภาพหมุน
data-slide
และแอตทริบิวต์data-slide-to
ระบุสไลด์ที่จะไป
แอตทริบิวต์data-slide
ยอมรับสองค่า: ก่อนหน้าหรือ
ถัดไปในขณะที่
data-slide-to
ยอมรับตัวเลข
ตัวอย่าง
<!-- Carousel -->
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Carousel Indicators -->
<li data-target="#myCarousel" data-slide-to="1"></li>
<!-- Carousel Controls -->
<a class="left carousel-control" href="#myCarousel" data-slide="prev">
ผ่าน JavaScript
เปิดใช้งานด้วยตนเองด้วย:
ตัวอย่าง
// Activate Carousel
$("#myCarousel").carousel();
// Enable Carousel Indicators
$(".item").click(function(){
$("#myCarousel").carousel(1);
});
// Enable Carousel Controls
$(".left").click(function(){
$("#myCarousel").carousel("prev");
});
ตัวเลือกม้าหมุน
ตัวเลือกสามารถส่งผ่านแอตทริบิวต์ข้อมูลหรือ JavaScript สำหรับแอตทริบิวต์ข้อมูล ให้ผนวกชื่อตัวเลือกกับ data- เช่นเดียวกับใน data-interval=""
Name | Type | Default | Description | Try it |
---|---|---|---|---|
interval | number, or the boolean false | 5000 |
Specifies the delay (in milliseconds) between each slide. Note: Set interval to false to stop the items from automatically sliding |
|
pause | string, or the boolean false | "hover" | Pauses the carousel from going through the next slide when the mouse pointer enters the carousel, and resumes the sliding when the mouse pointer leaves the carousel Note: Set pause to false to stop the ability to pause on hover |
|
wrap | boolean | true | Specifies whether the carousel should go through all slides continuously, or stop at the last slide
|
วิธีการหมุน
ตารางต่อไปนี้แสดงรายการวิธีวงล้อที่ใช้ได้ทั้งหมด
Method | Description | Try it |
---|---|---|
.carousel(options) | Activates the carousel with an option. See options above for valid values | |
.carousel("cycle") | Goes through the carousel items from left to right | |
.carousel("pause") | Stops the carousel from going through items | |
.carousel(number) | Goes to a specified item (zero-based: first item is 0, second item is 1, etc..) | |
.carousel("prev") | Goes to the previous item | |
.carousel("next") | Goes to the next item |
เหตุการณ์ม้าหมุน
ตารางต่อไปนี้แสดงรายการเหตุการณ์ภาพหมุนที่มีอยู่ทั้งหมด
Event | Description | Try it |
---|---|---|
slide.bs.carousel | Occurs when the carousel is about to slide from one item to another | |
slid.bs.carousel | Occurs when the carousel has finished sliding from one item to another |
ตัวอย่างเพิ่มเติม
คำบรรยายภาพสไลด์
เพิ่ม<div class="carousel-caption">
ใน<div
class="item">
แต่ละสไลด์เพื่อสร้างคำอธิบายภาพสำหรับแต่ละสไลด์:
ตัวอย่าง
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<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>
<li data-target="#myCarousel" data-slide-to="3"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="img_chania.jpg" alt="Chania">
<div class="carousel-caption">
<h3>Chania</h3>
<p>The atmosphere in Chania has a touch of Florence and Venice.</p>
</div>
</div>
<div class="item">
<img src="img_chania2.jpg" alt="Chania">
<div class="carousel-caption">
<h3>Chania</h3>
<p>The atmosphere in Chania has a touch of Florence and Venice.</p>
</div>
</div>
<div class="item">
<img src="img_flower.jpg" alt="Flower">
<div class="carousel-caption">
<h3>Flowers</h3>
<p>Beautiful flowers in Kolymbari, Crete.</p>
</div>
</div>
<div class="item">
<img src="img_flower2.jpg" alt="Flower">
<div class="carousel-caption">
<h3>Flowers</h3>
<p>Beautiful flowers in Kolymbari, Crete.</p>
</div>
</div>
</div>
<!-- Left and right controls -->
<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>