


Learn about various image carousel effects in Bootstrap in one article
This article will take you through the image carousel in Bootstrap and introduce the use of the Carousel image carousel component. I hope it will be helpful to everyone!
1 Carousel component
Carousel (Carousel) is a slide show component used to display elements, images or text slides (such as carousel).
The carousel is a slideshow for looping through a series of content, built using css3d transforms and a bit of JavaScript. It can handle a range of images, text or custom markup. It also includes support for previous/next controls and indicators. [Related recommendation: "bootstrap Tutorial"]
In browsers that support the page visibility API, when the user cannot see the web page (for example, the browser tab is inactive, browser window minimized, etc.), the carousel will avoid sliding.
Carousels do not automatically normalize the size of slides. Therefore, you may need to use additional universal categories or custom styles to resize your content appropriately. Although carousels support previous/next controls and indicators, they are not required. Can be added and customized as needed.
2 Examples of different forms of carousels
2.1 Slide-only carousel
This is a slide-only carousel. Please note the presence of .d-block and .w-50 on the carousel image to avoid browser default image alignment. The following code changes an image every 5 seconds.
<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="keywords" content=""> <meta name="description" content=""> <link href="../bootstrap5/bootstrap.min.css" rel="stylesheet"> <title>轮播</title> </head> <body> <div> <br><br><br> <div id="carouselExampleSlidesOnly" class="carousel slide" data-bs-ride="carousel"> <div> <div class="carousel-item active"> <img class="d-block w-100 lazy" src="/static/imghwm/default1.png" data-src="../pic/3.jpg" alt="..."> </div> <div> <img class="d-block w-100 lazy" src="/static/imghwm/default1.png" data-src="../pic/4.jpg" alt="..."> </div> <div> <img class="d-block w-100 lazy" src="/static/imghwm/default1.png" data-src="../pic/6.jpg" alt="..."> </div> </div> </div> </div> <script src="../bootstrap5/bootstrap.bundle.min.js" ></script> </body> </html>
2.2 Bring the previous and next controls
Add the previous and next controls. We recommend using the button element, but you can also use the a element with role="button". It should be noted that to set the image size and width, you need to set the size of the carousel container. The image setting must be w-100 to fill the container, otherwise the next one may not be visible.
<div id="carouselExampleControls" class="carousel slide w-50" data-bs-ride="carousel"> <div class="carousel-inner"> <div class="carousel-item active"> <img class="d-block w-100 lazy" src="/static/imghwm/default1.png" data-src="../pic/3.jpg" alt="..."> </div> <div class="carousel-item"> <img class="d-block w-100 lazy" src="/static/imghwm/default1.png" data-src="../pic/4.jpg" alt="..."> </div> <div class="carousel-item"> <img class="d-block w-100 lazy" src="/static/imghwm/default1.png" data-src="../pic/6.jpg" alt="..."> </div> </div> <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> </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> </button> </div>
The greater than and less than signs on both sides of the picture are the previous and next controls.
2.3 With indicator
The indicator is the three white horizontal bars in the picture below. Click to switch directly to the corresponding picture.
<div id="carouselExampleIndicators" class="carousel slide w-50" data-bs-ride="carousel"> <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"> <img class="d-block w-100 lazy" src="/static/imghwm/default1.png" data-src="../pic/3.jpg" alt="..."> </div> <div class="carousel-item"> <img class="d-block w-100 lazy" src="/static/imghwm/default1.png" data-src="../pic/4.jpg" alt="..."> </div> <div class="carousel-item"> <img class="d-block w-100 lazy" src="/static/imghwm/default1.png" data-src="../pic/6.jpg" alt="..."> </div> </div> <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> </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> </button> </div>
2.4 With subtitles
Use carousel-caption in any carousel-item to add subtitles to the slide. You can optionally hide them easily on smaller viewports using the display generic class, as shown below, which will initially be hidden with d-none and redisplayed on medium-sized devices using d-md-block.
<div id="carouselExampleCaptions" class="carousel slide w-50" data-bs-ride="carousel"> <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"> <img class="d-block w-100 lazy" src="/static/imghwm/default1.png" data-src="../pic/3.jpg" alt="..."> <div class="carousel-caption d-none d-md-block"> <h5 id="第一个幻灯片">第一个幻灯片</h5> <p>一枝红艳露凝香,云雨巫山枉断肠。<br>——唐代李白的《清平调·其二》</p> </div> </div> <div class="carousel-item"> <img class="d-block w-100 lazy" src="/static/imghwm/default1.png" data-src="../pic/4.jpg" alt="..."> <div class="carousel-caption d-none d-md-block"> <h5 id="第二个幻灯片">第二个幻灯片</h5> <p>南国有佳人,容华若桃李。<br>——汉曹植的《杂诗七首·其四》</p> </div> </div> <div class="carousel-item"> <img class="d-block w-100 lazy" src="/static/imghwm/default1.png" data-src="../pic/6.jpg" alt="..."> <div class="carousel-caption d-none d-md-block"> <h5 id="第三个幻灯片">第三个幻灯片</h5> <p>云想衣裳花想容,春风拂槛露华浓。<br> ——唐代李白的《清平调·其一》</p> </div> </div> </div> <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> </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> </button> </div>
2.5 Fade in and out
Add carousel-fade to the carousel container to use fade in and fade out instead of sliding animation effects. This part will not be demonstrated, including the last two, which are all a matter of parameters.
<div id="carouselExampleFade" class="carousel slide carousel-fade" data-bs-ride="carousel">
2.6 Set time interval
Add data-bs-interval="" on carousel-item to change the delay time of automatically looping to the next item. This parameter needs to be set in each arousel-item. The time unit is milliseconds. If the setting interval is 5 seconds, it will be 5000. Below is the setting interval of 10 seconds.
<div class="carousel-item active" data-bs-interval="10000">
2.7 Disable touch switching
The carousel component supports left/right swiping on touch screen devices to move between slides. This can be disabled using the data-bs-touch attribute. The example below includes neither the data-bs-ride attribute and has data-bs-interval="false" so it won't autoplay.
<div id="carouselExampleControlsNoTouching" class="carousel slide" data-bs-touch="false" data-bs-interval="false">
2.8 Dark variant
Add carousel-dark on carousel to get dark controls, indicators and subtitles. The controls have been inverted from their default white fill via the CSS property filter. Subtitles and controls have additional variables for customizing color and background-color.
Let’s take the example of 22.2.4 and add carousel-dark as an example to check the effect
<div id="carouselExampleCaptions" class="carousel carousel-dark slide w-50" data-bs-ride="carousel">
Because the color of the selected picture itself is a bit dark, so use this effect No, pictures with bright colors will look better. You can try it.
For more knowledge about bootstrap, please visit: bootstrap basic tutorial! !
The above is the detailed content of Learn about various image carousel effects in Bootstrap in one article. For more information, please follow other related articles on the PHP Chinese website!

Bootstrap is an open source front-end framework for creating modern, responsive, and user-friendly websites. 1) It provides grid systems and predefined styles to simplify layout and development. 2) Mobile-first design ensures compatibility and performance. 3) Through custom styles and components, the website can be personalized. 4) Performance optimization and best practices include selective loading and responsive images. 5) Common errors such as layout problems and style conflicts can be resolved through debugging techniques.

Bootstrap is an open source front-end framework developed by Twitter, suitable for building responsive websites quickly. 1) Its grid system is based on a 12-column structure, allowing for the creation of flexible layouts. 2) Responsive design function enables the website to adapt to different devices. 3) The basic usage includes building a navigation bar, and the advanced usage involves card components. 4) Common errors such as misuse of grid systems can be avoided by correctly setting the column width. 5) Performance optimization includes loading only necessary components, using CDN and file compression. 6) Best practices emphasize tidy code, custom styles and responsive design.

The reason for combining Bootstrap and React is their complementarity: 1. Bootstrap provides predefined styles and components to simplify UI design; 2. React improves efficiency and performance through component development and virtual DOM. Use it in conjunction to enjoy fast UI construction and complex interaction management.

Bootstrap is an open source front-end framework based on HTML, CSS and JavaScript, designed to help developers quickly build responsive websites. Its design philosophy is "mobile first", providing a wealth of predefined components and tools, such as grid systems, buttons, forms, navigation bars, etc., simplifying the front-end development process, improving development efficiency, and ensuring the responsiveness and consistency of the website. Using Bootstrap can start with a simple page and gradually add advanced components such as cards and modal boxes. Best practices for optimizing performance include customizing Bootstrap, using CDNs, and avoiding overuse of class names.

React and Bootstrap can be seamlessly integrated to enhance user interface design. 1) Install dependency package: npminstallbootstrapreact-bootstrap. 2) Import the CSS file: import'bootstrap/dist/css/bootstrap.min.css'. 3) Use Bootstrap components such as buttons and navigation bars. With this combination, developers can leverage React's flexibility and Bootstrap's style library to create a beautiful and efficient user interface.

The steps to integrate Bootstrap into a React project include: 1. Install the Bootstrap package, 2. Import the CSS file, 3. Use Bootstrap class name to style elements, 4. Use React-Bootstrap or reactstrap library to use Bootstrap's JavaScript components. This integration utilizes React's componentization and Bootstrap's style system to achieve efficient UI development.

Bootstrapisapowerfulframeworkthatsimplifiescreatingresponsive,mobile-firstwebsites.Itoffers:1)agridsystemforadaptablelayouts,2)pre-styledelementslikebuttonsandforms,and3)JavaScriptcomponentssuchascarouselsforenhancedinteractivity.

Bootstrap is a front-end framework developed by Twitter that integrates HTML, CSS and JavaScript to help developers quickly build responsive websites. Its core functions include: Grid system and layout: based on 12-column design, using flexbox layout, and supporting responsive pages of different device sizes. Components and styles: Provide a rich library of component, such as buttons, modal boxes, etc., and you can achieve beautiful effects by adding class names. How it works: Rely on CSS and JavaScript, CSS uses LESS or SASS preprocessors, and JavaScript relies on jQuery to achieve interactive and dynamic effects. Through these features, Bootstrap greatly improves development


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download
The most popular open source editor

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Zend Studio 13.0.1
Powerful PHP integrated development environment

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
