运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往空间
<!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Example</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script> <style> .carousel-inner > .item > img, .carousel-inner > .item > a > img { width: 70%; margin: auto; } </style> </head> <body> <div class="container"> <h2>Carousel Methods</h2> <p>The <strong>cycle</strong> method goes through the carousel items from left to right (slides automatically).</p> <p>The <strong>pause</strong> method stops the carousel from going through items.</p> <button type="button" id="myBtn" class="btn btn-success btn-lg">Slide through items (cycle)</button> <button type="button" id="myBtn2" class="btn btn-danger btn-lg">Stop slide (pause)</button><br><br> <div id="myCarousel" class="carousel slide" data-interval="500"> <!-- Indicators --> <ol class="carousel-indicators"> <li class="item1 active"></li> <li class="item2"></li> <li class="item3"></li> <li class="item4"></li> </ol> <!-- Wrapper for slides --> <div class="carousel-inner" role="listbox"> <div class="item active"> <img src="img_chania.jpg" alt="Chania" width="460" height="345"> </div> <div class="item"> <img src="img_chania2.jpg" alt="Chania" width="460" height="345"> </div> <div class="item"> <img src="img_flower.jpg" alt="Flower" width="460" height="345"> </div> <div class="item"> <img src="img_flower2.jpg" alt="Flower" width="460" height="345"> </div> </div> <!-- Left and right controls --> <a class="left carousel-control" href="#myCarousel" role="button"> <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span> <span class="sr-only">Previous</span> </a> <a class="right carousel-control" href="#myCarousel" role="button"> <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> <span class="sr-only">Next</span> </a> </div> </div> <script> $(document).ready(function(){ // Activate Carousel $("#myCarousel").carousel("pause"); // Click on the button to start sliding $("#myBtn").click(function(){ $("#myCarousel").carousel("cycle"); }); // Click on the button to stop sliding $("#myBtn2").click(function(){ $("#myCarousel").carousel("pause"); }); // Enable Carousel Indicators $(".item1").click(function(){ $("#myCarousel").carousel(0); }); $(".item2").click(function(){ $("#myCarousel").carousel(1); }); $(".item3").click(function(){ $("#myCarousel").carousel(2); }); $(".item4").click(function(){ $("#myCarousel").carousel(3); }); // Enable Carousel Controls $(".left").click(function(){ $("#myCarousel").carousel("prev"); }); $(".right").click(function(){ $("#myCarousel").carousel("next"); }); }); </script> </body> </html>