微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

需要帮助制作 Bootstrap Carousel它不起作用

如何解决需要帮助制作 Bootstrap Carousel它不起作用

我目前被困在我的项目的一部分上,我似乎无法在每个图像之间进行轮播切换。代码现在看起来像这样:

<!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">
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-wEmeIV1mKuiNpC+IOBjI7aAzPcEZeedi5yW5f2yOq55WWLwNGmvvx4Um1vskeMj0" crossorigin="anonymous">
        <link href = "css/style.css" rel = "stylesheet" type = "text/css">
        <title>Document</title>
    </head>
    <body>
        <main id = "main-text">
                <nav class = 'navbar navbar-dark bg-dark'>
                    <div id = 'top-nav' class = 'container'>
                        <img src = '/vapeShop/images/img1.png' alt = '' width = '15%' height = '15%'>
                        <a id = 'nav-link light' class = 'navbar link' href = '#'>
                            Brand Name
                        </a>
                        <a id = 'nav-link light' class = 'navbar-link' href = '#'>
                            Locations
                        </a>
                    </div>
                </nav>

                <div id="topCarousel" class="carousel slide mt-4 bg-dark" data-ride = 'carousel'>
                    <div class="carousel-inner">
                      <div class="carousel-item active">
                        <img id = 'carousel-imgs' class="d-block w-100" src="/vapeShop/images/img2.png" alt="First slide">
                      </div>
                      <div class="carousel-item">
                        <img id = 'carousel-imgs' class="d-block w-100" src="/vapeShop/images/img3.jpg" alt="Second slide">
                      </div>
                      <div class="carousel-item">
                        <img id = 'carousel-imgs' class="d-block w-100" src="/vapeShop/images/img4.jpg" alt="Third slide">
                      </div>
                    </div>
                    <a class="carousel-control-prev" href="#topCarousel" role="button" data-slide="prev">
                      <span class="carousel-control-prev-icon" aria-hidden="true"></span>
                      <span class="sr-only"></span>
                    </a>
                    <a class="carousel-control-next" href="#topCarousel" role="button" data-slide="next">
                      <span class="carousel-control-next-icon" aria-hidden="true"></span>
                      <span class="sr-only"></span>
                    </a>
                </div>
            </main>
            
        </body>
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-p34f1UUtsS3wqzfto5wAAmdvj+osOnFyQFpp4Ua3gs/ZVWx6oOypYoCJhGGScy+8" crossorigin="anonymous"></script>
        <script src = "js/app.js"></script>
        </html>

每当我点击人字形时,旋转木马只是拒绝进入下一张图片。有什么我遗漏的吗?

解决方法

    <!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">
      <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-wEmeIV1mKuiNpC+IOBjI7aAzPcEZeedi5yW5f2yOq55WWLwNGmvvx4Um1vskeMj0" crossorigin="anonymous">
      <link href="css/style.css" rel="stylesheet" type="text/css">
      <title>Document</title>
   </head>
   <body>
      <!-- begin snippet: js hide: false console: true babel: false -->
      <!-- language: lang-html -->
      <main id="main-text">
         <nav class='navbar navbar-dark bg-dark'>
            <div id='top-nav' class='container'>
               <img src='/vapeShop/images/img1.png' alt='' width='15%' height='15%'>
               <a id='nav-link light' class='navbar link' href='#'>
               Brand Name
               </a>
               <a id='nav-link light' class='navbar-link' href='#'>
               Locations
               </a>
            </div>
         </nav>
         <div id="topCarousel" class="carousel slide mt-4 bg-dark" data-ride='carousel'>
            <div class="carousel-inner">
               <div class="carousel-item active">
                  <img id='carousel-imgs' class="d-block w-100" src="/vapeShop/images/img2.png" alt="First slide">
               </div>
               <div class="carousel-item">
                  <img id='carousel-imgs' class="d-block w-100" src="/vapeShop/images/img3.jpg" alt="Second slide">
               </div>
               <div class="carousel-item">
                  <img id='carousel-imgs' class="d-block w-100" src="/vapeShop/images/img4.jpg" alt="Third slide">
               </div>
            </div>
            <a class="carousel-control-prev" href="#topCarousel" role="button" data-bs-target="#topCarousel" data-bs-slide="prev">
            <span class="carousel-control-prev-icon" aria-hidden="true"></span>
            <span class="sr-only"></span>
            </a>
            <a class="carousel-control-next" href="#topCarousel" role="button" data-bs-target="#topCarousel" data-bs-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="sr-only"></span>
            </a>
         </div>
      </main>
   </body>
   <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-p34f1UUtsS3wqzfto5wAAmdvj+osOnFyQFpp4Ua3gs/ZVWx6oOypYoCJhGGScy+8" crossorigin="anonymous"></script>
   <script src="js/app.js"></script>
</html>

您只需要在下一个链接中添加 data-bs-target="#topCarousel" data-bs-slide="prev" 属性。

<a class="carousel-control-prev" href="#topCarousel" role="button" data-bs-target="#topCarousel" data-bs-slide="prev">
                <span class="carousel-control-prev-icon" aria-hidden="true"></span>
                <span class="sr-only"></span>
            </a>
            <a class="carousel-control-next" href="#topCarousel" role="button" data-bs-target="#topCarousel" data-bs-slide="next">
                <span class="carousel-control-next-icon" aria-hidden="true"></span>
                <span class="sr-only"></span>
            </a>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。