Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Activate Bootstrap 3 Carousel via JavaScript</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ // Activate carousel $("#myCarousel").carousel(); // Enable carousel control $(".left").click(function(){ $("#myCarousel").carousel('prev'); }); $(".right").click(function(){ $("#myCarousel").carousel('next'); }); // Enable carousel indicators $(".slide-one").click(function(){ $("#myCarousel").carousel(0); }); $(".slide-two").click(function(){ $("#myCarousel").carousel(1); }); $(".slide-three").click(function(){ $("#myCarousel").carousel(2); }); }); </script> <style type="text/css"> .carousel{ background: #2f4357; margin-top: 20px; } .carousel .item{ min-height: 280px; /* Prevent carousel from being distorted if for some reason image doesn't load */ } .carousel .item img{ margin: 0 auto; /* Align slide image horizontally center */ } .bs-example{ margin: 20px; } </style> </head> <body> <div class="bs-example"> <div id="myCarousel" class="carousel slide" data-interval="3000" data-ride="carousel"> <!-- Carousel indicators --> <ol class="carousel-indicators"> <li class="slide-one active"></li> <li class="slide-two"></li> <li class="slide-three"></li> </ol> <!-- Wrapper for carousel items --> <div class="carousel-inner"> <div class="active item"> <img src="/examples/images/slide1.png" alt="First Slide"> <div class="carousel-caption"> <h3>First slide label</h3> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p> </div> </div> <div class="item"> <img src="/examples/images/slide2.png" alt="Second Slide"> <div class="carousel-caption"> <h3>Second slide label</h3> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p> </div> </div> <div class="item"> <img src="/examples/images/slide3.png" alt="Third Slide"> <div class="carousel-caption"> <h3>Third slide label</h3> <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur.</p> </div> </div> </div> <!-- Carousel controls --> <a class="carousel-control left"> <span class="glyphicon glyphicon-chevron-left"></span> </a> <a class="carousel-control right"> <span class="glyphicon glyphicon-chevron-right"></span> </a> </div> </div> </body> </html>