diff options
| author | Patrick H. Lauke <[email protected]> | 2021-05-04 12:46:06 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-05-04 12:46:06 +0100 |
| commit | 8865a8ab1c7157ab81bf49afa62b75f36daee46d (patch) | |
| tree | 97ef78f2ea8e07aab50014176d061fe3c1d49134 /site/content/docs/5.0/components/carousel.md | |
| parent | 018ee6a3b50b958ddb49657086cd9168abf5a485 (diff) | |
| parent | 7ea6578773cb1b7f5cfb8fb41321b3fa10349daf (diff) | |
| download | bootstrap-jo-docs-thanks-page.tar.xz bootstrap-jo-docs-thanks-page.zip | |
Merge branch 'main' into jo-docs-thanks-pagejo-docs-thanks-page
Diffstat (limited to 'site/content/docs/5.0/components/carousel.md')
| -rw-r--r-- | site/content/docs/5.0/components/carousel.md | 148 |
1 files changed, 91 insertions, 57 deletions
diff --git a/site/content/docs/5.0/components/carousel.md b/site/content/docs/5.0/components/carousel.md index 85ee9eb44..9ad7294ec 100644 --- a/site/content/docs/5.0/components/carousel.md +++ b/site/content/docs/5.0/components/carousel.md @@ -22,7 +22,7 @@ Please be aware that nested carousels are not supported, and carousels are gener Carousels don't automatically normalize slide dimensions. As such, you may need to use additional utilities or custom styles to appropriately size content. While carousels support previous/next controls and indicators, they're not explicitly required. Add and customize as you see fit. -**The `.active` class needs to be added to one of the slides** otherwise the carousel will not be visible. Also be sure to set a unique id on the `.carousel` for optional controls, especially if you're using multiple carousels on a single page. Control and indicator elements must have a `data-bs-target` attribute (or `href` for links) that matches the id of the `.carousel` element. +**The `.active` class needs to be added to one of the slides** otherwise the carousel will not be visible. Also be sure to set a unique `id` on the `.carousel` for optional controls, especially if you're using multiple carousels on a single page. Control and indicator elements must have a `data-bs-target` attribute (or `href` for links) that matches the `id` of the `.carousel` element. ### Slides only @@ -46,7 +46,7 @@ Here's a carousel with slides only. Note the presence of the `.d-block` and `.w- ### With controls -Adding in the previous and next controls: +Adding in the previous and next controls. We recommend using `<button>` elements, but you can also use `<a>` elements with `role="button"`. {{< example >}} <div id="carouselExampleControls" class="carousel slide" data-bs-ride="carousel"> @@ -61,14 +61,14 @@ Adding in the previous and next controls: {{< placeholder width="800" height="400" class="bd-placeholder-img-lg d-block w-100" color="#333" background="#555" text="Third slide" >}} </div> </div> - <a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-bs-slide="prev"> + <button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleControls" data-bs-slide="prev"> <span class="carousel-control-prev-icon" aria-hidden="true"></span> <span class="visually-hidden">Previous</span> - </a> - <a class="carousel-control-next" href="#carouselExampleControls" role="button" data-bs-slide="next"> + </button> + <button class="carousel-control-next" type="button" data-bs-target="#carouselExampleControls" data-bs-slide="next"> <span class="carousel-control-next-icon" aria-hidden="true"></span> <span class="visually-hidden">Next</span> - </a> + </button> </div> {{< /example >}} @@ -78,11 +78,11 @@ You can also add the indicators to the carousel, alongside the controls, too. {{< example >}} <div id="carouselExampleIndicators" class="carousel slide" data-bs-ride="carousel"> - <ol class="carousel-indicators"> - <li data-bs-target="#carouselExampleIndicators" data-bs-slide-to="0" class="active"></li> - <li data-bs-target="#carouselExampleIndicators" data-bs-slide-to="1"></li> - <li data-bs-target="#carouselExampleIndicators" data-bs-slide-to="2"></li> - </ol> + <div class="carousel-indicators"> + <button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1"></button> + <button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="1" aria-label="Slide 2"></button> + <button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="2" aria-label="Slide 3"></button> + </div> <div class="carousel-inner"> <div class="carousel-item active"> {{< placeholder width="800" height="400" class="bd-placeholder-img-lg d-block w-100" color="#555" background="#777" text="First slide" >}} @@ -94,14 +94,14 @@ You can also add the indicators to the carousel, alongside the controls, too. {{< placeholder width="800" height="400" class="bd-placeholder-img-lg d-block w-100" color="#333" background="#555" text="Third slide" >}} </div> </div> - <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-bs-slide="prev"> + <button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide="prev"> <span class="carousel-control-prev-icon" aria-hidden="true"></span> <span class="visually-hidden">Previous</span> - </a> - <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-bs-slide="next"> + </button> + <button class="carousel-control-next" type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide="next"> <span class="carousel-control-next-icon" aria-hidden="true"></span> <span class="visually-hidden">Next</span> - </a> + </button> </div> {{< /example >}} @@ -111,42 +111,42 @@ Add captions to your slides easily with the `.carousel-caption` element within a {{< example >}} <div id="carouselExampleCaptions" class="carousel slide" data-bs-ride="carousel"> - <ol class="carousel-indicators"> - <li data-bs-target="#carouselExampleCaptions" data-bs-slide-to="0" class="active"></li> - <li data-bs-target="#carouselExampleCaptions" data-bs-slide-to="1"></li> - <li data-bs-target="#carouselExampleCaptions" data-bs-slide-to="2"></li> - </ol> + <div class="carousel-indicators"> + <button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1"></button> + <button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="1" aria-label="Slide 2"></button> + <button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="2" aria-label="Slide 3"></button> + </div> <div class="carousel-inner"> <div class="carousel-item active"> {{< placeholder width="800" height="400" class="bd-placeholder-img-lg d-block w-100" color="#555" background="#777" text="First slide" >}} <div class="carousel-caption d-none d-md-block"> <h5>First slide label</h5> - <p>Nulla vitae elit libero, a pharetra augue mollis interdum.</p> + <p>Some representative placeholder content for the first slide.</p> </div> </div> <div class="carousel-item"> {{< placeholder width="800" height="400" class="bd-placeholder-img-lg d-block w-100" color="#444" background="#666" text="Second slide" >}} <div class="carousel-caption d-none d-md-block"> <h5>Second slide label</h5> - <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p> + <p>Some representative placeholder content for the second slide.</p> </div> </div> <div class="carousel-item"> {{< placeholder width="800" height="400" class="bd-placeholder-img-lg d-block w-100" color="#333" background="#555" text="Third slide" >}} <div class="carousel-caption d-none d-md-block"> <h5>Third slide label</h5> - <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur.</p> + <p>Some representative placeholder content for the third slide.</p> </div> </div> </div> - <a class="carousel-control-prev" href="#carouselExampleCaptions" role="button" data-bs-slide="prev"> + <button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide="prev"> <span class="carousel-control-prev-icon" aria-hidden="true"></span> <span class="visually-hidden">Previous</span> - </a> - <a class="carousel-control-next" href="#carouselExampleCaptions" role="button" data-bs-slide="next"> + </button> + <button class="carousel-control-next" type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide="next"> <span class="carousel-control-next-icon" aria-hidden="true"></span> <span class="visually-hidden">Next</span> - </a> + </button> </div> {{< /example >}} @@ -167,14 +167,14 @@ Add `.carousel-fade` to your carousel to animate slides with a fade transition i {{< placeholder width="800" height="400" class="bd-placeholder-img-lg d-block w-100" color="#333" background="#555" text="Third slide" >}} </div> </div> - <a class="carousel-control-prev" href="#carouselExampleFade" role="button" data-bs-slide="prev"> + <button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleFade" data-bs-slide="prev"> <span class="carousel-control-prev-icon" aria-hidden="true"></span> <span class="visually-hidden">Previous</span> - </a> - <a class="carousel-control-next" href="#carouselExampleFade" role="button" data-bs-slide="next"> + </button> + <button class="carousel-control-next" type="button" data-bs-target="#carouselExampleFade" data-bs-slide="next"> <span class="carousel-control-next-icon" aria-hidden="true"></span> <span class="visually-hidden">Next</span> - </a> + </button> </div> {{< /example >}} @@ -195,14 +195,42 @@ Add `data-bs-interval=""` to a `.carousel-item` to change the amount of time to {{< placeholder width="800" height="400" class="bd-placeholder-img-lg d-block w-100" color="#333" background="#555" text="Third slide" >}} </div> </div> - <a class="carousel-control-prev" href="#carouselExampleInterval" role="button" data-bs-slide="prev"> + <button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleInterval" data-bs-slide="prev"> <span class="carousel-control-prev-icon" aria-hidden="true"></span> <span class="visually-hidden">Previous</span> - </a> - <a class="carousel-control-next" href="#carouselExampleInterval" role="button" data-bs-slide="next"> + </button> + <button class="carousel-control-next" type="button" data-bs-target="#carouselExampleInterval" data-bs-slide="next"> <span class="carousel-control-next-icon" aria-hidden="true"></span> <span class="visually-hidden">Next</span> - </a> + </button> +</div> +{{< /example >}} + +### Disable touch swiping + +Carousels support swiping left/right on touchscreen devices to move between slides. This can be disabled using the `data-bs-touch` attribute. The example below also does not include the `data-bs-ride` attribute and has `data-bs-interval="false"` so it doesn't autoplay. + +{{< example >}} +<div id="carouselExampleControlsNoTouching" class="carousel slide" data-bs-touch="false" data-bs-interval="false"> + <div class="carousel-inner"> + <div class="carousel-item active"> + {{< placeholder width="800" height="400" class="bd-placeholder-img-lg d-block w-100" color="#555" background="#777" text="First slide" >}} + </div> + <div class="carousel-item"> + {{< placeholder width="800" height="400" class="bd-placeholder-img-lg d-block w-100" color="#444" background="#666" text="Second slide" >}} + </div> + <div class="carousel-item"> + {{< placeholder width="800" height="400" class="bd-placeholder-img-lg d-block w-100" color="#333" background="#555" text="Third slide" >}} + </div> + </div> + <button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleControlsNoTouching" data-bs-slide="prev"> + <span class="carousel-control-prev-icon" aria-hidden="true"></span> + <span class="visually-hidden">Previous</span> + </button> + <button class="carousel-control-next" type="button" data-bs-target="#carouselExampleControlsNoTouching" data-bs-slide="next"> + <span class="carousel-control-next-icon" aria-hidden="true"></span> + <span class="visually-hidden">Next</span> + </button> </div> {{< /example >}} @@ -212,45 +240,55 @@ Add `.carousel-dark` to the `.carousel` for darker controls, indicators, and cap {{< example >}} <div id="carouselExampleDark" class="carousel carousel-dark slide" data-bs-ride="carousel"> - <ol class="carousel-indicators"> - <li data-bs-target="#carouselExampleDark" data-bs-slide-to="0" class="active"></li> - <li data-bs-target="#carouselExampleDark" data-bs-slide-to="1"></li> - <li data-bs-target="#carouselExampleDark" data-bs-slide-to="2"></li> - </ol> + <div class="carousel-indicators"> + <button type="button" data-bs-target="#carouselExampleDark" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1"></button> + <button type="button" data-bs-target="#carouselExampleDark" data-bs-slide-to="1" aria-label="Slide 2"></button> + <button type="button" data-bs-target="#carouselExampleDark" data-bs-slide-to="2" aria-label="Slide 3"></button> + </div> <div class="carousel-inner"> <div class="carousel-item active" data-bs-interval="10000"> {{< placeholder width="800" height="400" class="bd-placeholder-img-lg d-block w-100" color="#aaa" background="#f5f5f5" text="First slide" >}} <div class="carousel-caption d-none d-md-block"> <h5>First slide label</h5> - <p>Nulla vitae elit libero, a pharetra augue mollis interdum.</p> + <p>Some representative placeholder content for the first slide.</p> </div> </div> <div class="carousel-item" data-bs-interval="2000"> {{< placeholder width="800" height="400" class="bd-placeholder-img-lg d-block w-100" color="#bbb" background="#eee" text="Second slide" >}} <div class="carousel-caption d-none d-md-block"> <h5>Second slide label</h5> - <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p> + <p>Some representative placeholder content for the second slide.</p> </div> </div> <div class="carousel-item"> {{< placeholder width="800" height="400" class="bd-placeholder-img-lg d-block w-100" color="#999" background="#e5e5e5" text="Third slide" >}} <div class="carousel-caption d-none d-md-block"> <h5>Third slide label</h5> - <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur.</p> + <p>Some representative placeholder content for the third slide.</p> </div> </div> </div> - <a class="carousel-control-prev" href="#carouselExampleDark" role="button" data-bs-slide="prev"> + <button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleDark" data-bs-slide="prev"> <span class="carousel-control-prev-icon" aria-hidden="true"></span> <span class="visually-hidden">Previous</span> - </a> - <a class="carousel-control-next" href="#carouselExampleDark" role="button" data-bs-slide="next"> + </button> + <button class="carousel-control-next" type="button" data-bs-target="#carouselExampleDark" data-bs-slide="next"> <span class="carousel-control-next-icon" aria-hidden="true"></span> <span class="visually-hidden">Next</span> - </a> + </button> </div> {{< /example >}} +## Custom transition + +The transition duration of `.carousel-item` can be changed with the `$carousel-transition-duration` Sass variable before compiling or custom styles if you're using the compiled CSS. If multiple transitions are applied, make sure the transform transition is defined first (eg. `transition: transform 2s ease, opacity .5s ease-out`). + +## Sass + +### Variables + +{{< scss-docs name="carousel-variables" file="scss/_variables.scss" >}} + ## Usage ### Via data attributes @@ -286,7 +324,7 @@ Options can be passed via data attributes or JavaScript. For data attributes, ap <td><code>interval</code></td> <td>number</td> <td><code>5000</code></td> - <td>The amount of time to delay between automatically cycling an item. If false, carousel will not automatically cycle.</td> + <td>The amount of time to delay between automatically cycling an item. If <code>false</code>, carousel will not automatically cycle.</td> </tr> <tr> <td><code>keyboard</code></td> @@ -297,15 +335,15 @@ Options can be passed via data attributes or JavaScript. For data attributes, ap <tr> <td><code>pause</code></td> <td>string | boolean</td> - <td><code>"hover"</code></td> - <td><p>If set to <code>"hover"</code>, pauses the cycling of the carousel on <code>mouseenter</code> and resumes the cycling of the carousel on <code>mouseleave</code>. If set to <code>false</code>, hovering over the carousel won't pause it.</p> - <p>On touch-enabled devices, when set to <code>"hover"</code>, cycling will pause on <code>touchend</code> (once the user finished interacting with the carousel) for two intervals, before automatically resuming. Note that this is in addition to the above mouse behavior.</p></td> + <td><code>'hover'</code></td> + <td><p>If set to <code>'hover'</code>, pauses the cycling of the carousel on <code>mouseenter</code> and resumes the cycling of the carousel on <code>mouseleave</code>. If set to <code>false</code>, hovering over the carousel won't pause it.</p> + <p>On touch-enabled devices, when set to <code>'hover'</code>, cycling will pause on <code>touchend</code> (once the user finished interacting with the carousel) for two intervals, before automatically resuming. Note that this is in addition to the above mouse behavior.</p></td> </tr> <tr> - <td><code>slide</code></td> + <td><code>ride</code></td> <td>string | boolean</td> <td><code>false</code></td> - <td>Autoplays the carousel after the user manually cycles the first item. If "carousel", autoplays the carousel on load.</td> + <td>Autoplays the carousel after the user manually cycles the first item. If set to <code>'carousel'</code>, autoplays the carousel on load.</td> </tr> <tr> <td><code>wrap</code></td> @@ -418,7 +456,3 @@ myCarousel.addEventListener('slide.bs.carousel', function () { // do something... }) ``` - -### Change transition duration - -The transition duration of `.carousel-item` can be changed with the `$carousel-transition` Sass variable before compiling or custom styles if you're using the compiled CSS. If multiple transitions are applied, make sure the transform transition is defined first (eg. `transition: transform 2s ease, opacity .5s ease-out`). |
