Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Bootstrap 4 Carousel Methods</title> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css"> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js"></script> <script> $(document).ready(function(){ // Initializes the carousel $(".start-slide").click(function(){ $("#myCarousel").carousel('cycle'); }); // Stops the carousel $(".pause-slide").click(function(){ $("#myCarousel").carousel('pause'); }); // Cycles to the previous item $(".prev-slide").click(function(){ $("#myCarousel").carousel('prev'); }); // Cycles to the next item $(".next-slide").click(function(){ $("#myCarousel").carousel('next'); }); // Cycles the carousel to a particular frame $(".slide-one").click(function(){ $("#myCarousel").carousel(0); }); $(".slide-two").click(function(){ $("#myCarousel").carousel(1); }); $(".slide-three").click(function(){ $("#myCarousel").carousel(2); }); }); </script> <style> .carousel{ background: #2f4357; margin-top: 20px; } .carousel-item{ text-align: center; min-height: 280px; /* Prevent carousel from being distorted if for some reason image doesn't load */ } </style> </head> <body> <div class="container-lg my-3"> <div id="myCarousel" class="carousel slide"> <!-- Wrapper for carousel items --> <div class="carousel-inner"> <div class="carousel-item active"> <img src="/examples/images/slide1.png" alt="First Slide"> <div class="carousel-caption d-none d-md-block"> <h5>First slide label</h5> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p> </div> </div> <div class="carousel-item"> <img src="/examples/images/slide2.png" alt="Second Slide"> <div class="carousel-caption d-none d-md-block"> <h5>Second slide label</h5> <p>Nulla vitae elit libero, a pharetra augue mollis interdum.</p> </div> </div> <div class="carousel-item"> <img src="/examples/images/slide3.png" alt="Third Slide"> <div class="carousel-caption d-none d-md-block"> <h5>First slide label</h5> <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur.</p> </div> </div> </div> </div> <!-- Carousel controls buttons --> <div class="text-center mt-2"> <input type="button" class="btn btn-info start-slide" value="Start"> <input type="button" class="btn btn-info pause-slide" value="Pause"> <input type="button" class="btn btn-info prev-slide" value="Previous Slide"> <input type="button" class="btn btn-info next-slide" value="Next Slide"> <input type="button" class="btn btn-info slide-one" value="Slide 1"> <input type="button" class="btn btn-info slide-two" value="Slide 2"> <input type="button" class="btn btn-info slide-three" value="Slide 3"> </div> </div> </body> </html>