Bootstrap 4 บทช่วยสอน

BS4 HOME BS4 เริ่มต้น BS4 คอนเทนเนอร์ BS4 Grid Basic BS4 วิชาการพิมพ์ BS4 สี ตาราง BS4 BS4 รูปภาพ BS4 Jumbotron การแจ้งเตือน BS4 ปุ่ม BS4 กลุ่มปุ่ม BS4 ป้าย BS4 แถบความคืบหน้า BS4 BS4 Spinners BS4 การแบ่งหน้า BS4 รายการกลุ่ม การ์ด BS4 BS4 ดรอปดาวน์ BS4 ยุบ BS4 Navs BS4 Navbar แบบฟอร์ม BS4 อินพุต BS4 กลุ่มอินพุต BS4 BS4 แบบฟอร์มที่กำหนดเอง BS4 ม้าหมุน BS4 โมดอล เคล็ดลับเครื่องมือ BS4 BS4 ป๊อปโอเวอร์ BS4 ขนมปังปิ้ง BS4 Scrollspy BS4 ยูทิลิตี้ BS4 Flex ไอคอน BS4 วัตถุสื่อ BS4 ตัวกรอง BS4

Bootstrap 4 Grid

ระบบกริด BS4 BS4 ซ้อน/แนวนอน BS4 Grid XSmall BS4 กริดขนาดเล็ก BS4 กริดขนาดกลาง BS4 กริดขนาดใหญ่ BS4 Grid XLarge ตัวอย่างกริด BS4

Bootstrap 4 อื่นๆ

เทมเพลตพื้นฐาน BS4 แบบฝึกหัด BS4 แบบทดสอบ BS4

Bootstrap 4 อ้างอิง

ทุกชั้นเรียน JS Alert ปุ่ม JS JS Carousel JS ยุบ JS Dropdown JS Modal JS Popover JS Scrollspy JS แท็บ JS Toasts JS Tooltip


Bootstrap 4 JS Carousel


คลาส CSS แบบหมุน

สำหรับบทแนะนำเกี่ยวกับ Carousels โปรดอ่านBootstrap Carousel Tutorialของเรา

Class Description
.carousel Creates a carousel
.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
.carousel-item Specifies the content of each slide
.carousel-control-prev Adds a left (previous) button to the carousel, which allows the user to go back between the slides
.carousel-control-next Adds a right (next) button to the carousel, which allows the user to go forward between the slides
.carousel-control-prev-icon Used together with .carousel-control-prev to create a "previous" button
.carousel-control-next-icon Used together with .carousel-control-next to create a "next" button
.carousel-caption Specifies a caption for the 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

ผ่าน 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="carousel-control-prev" href="#myCarousel" data-slide="prev">
  <span class="carousel-control-prev-icon"></span>
</a>

ผ่าน JavaScript

เปิดใช้งานด้วยตนเองด้วย:

ตัวอย่าง

// Activate Carousel
$("#myCarousel").carousel();

// Enable Carousel Indicators
$(".item").click(function(){
  $("#myCarousel").carousel(1);
});

// Enable Carousel Controls
$(".carousel-control-prev").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
keyboard boolean true Specifies whether the carousel should react to keyboard events:

  • true - the carousel can be navigated (next and previous) with the keyboard left and right arrows
  • false - the carousel can NOT be navigated with the keyboard left and right arrows
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

  • true - cycle continuously
  • false - stop at the last item

วิธีการหมุน

ตารางต่อไปนี้แสดงรายการวิธีวงล้อที่ใช้ได้ทั้งหมด

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
.carousel("dispose") Destroys a carousel

เหตุการณ์ม้าหมุน

ตารางต่อไปนี้แสดงรายการเหตุการณ์ภาพหมุนที่มีอยู่ทั้งหมด

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

เหตุการณ์สไลด์และสไลด์ยังมีคุณสมบัติเพิ่มเติม:

Property Description Try it
direction Returns the direction the carousel is sliding (left or right)
relatedTarget Returns the DOM element that is being slid into place as the active item
from Returns the index of where the previous item came from, when moving on to the next one
to Returns the index of the next item