我在轮播中滚动效果有问题。只是动画,简单的滚动工作,而动画则没有。
也许有人可以检查我的代码并修复^ _ ^谢谢。
image使用类carousel-image-1(2,3)添加CSS。我比较了官方引导站点上的示例,并且都比较了我的代码。也许我看不到错误



.carousel-item {
  height: 450px;
}

.carousel-image-1 {
  background: url(https://source.unsplash.com/random/560x560);
  background-size: cover;
}

.carousel-image-2 {
  background: url(https://source.unsplash.com/random/560x560);
  background-size: cover;
}

.carousel-image-3 {
  background: url(https://source.unsplash.com/random/560x560);
  background-size: cover;
}

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
    integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css"
    integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
  <link rel="stylesheet" href="/css/style.css">
  <title>Title</title>
</head>

<body>

  <!-- Showcase Slider-->

  <section class="showcase">
    <div id="myCarousel" class="carousel slide" data-ride="carousel">
      <ol class="carousel-indicators">
        <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
        <li data-target="#myCarousel" data-slide-to="1"></li>
        <li data-target="#myCarousel" data-slide-to="2"></li>
      </ol>
      <div class="carousel-inner">
        <div class="carousel-item carousel-image-1 active">
          <div class="container">
            <div class="carousel-caption d-none d-sm-block text-right mb-5">
              <h1 class="display-3">
                Heading One
              </h1>
              <p class="lead">Lorem, ipsum dolor sit amet consectetur adipisicing elit. Doloribus nostrum excepturi
                repellendus quos provident sit! Odio odit quo voluptatum aperiam.</p>
              <a href="#" class="btn btn-danger btn-lg">Sign Up Now</a>
            </div>
          </div>
        </div>

        <div class="carousel-item carousel-image-2 ">
          <div class="container">
            <div class="carousel-caption d-none d-sm-block  mb-5">
              <h1 class="display-3">
                Heading Two
              </h1>
              <p class="lead">Lorem, ipsum dolor sit amet consectetur adipisicing elit. Doloribus nostrum excepturi
                repellendus quos provident sit! Odio odit quo voluptatum aperiam.</p>
              <a href="#" class="btn btn-primary btn-lg">Learn More</a>
            </div>
          </div>
        </div>

        <div class="carousel-item carousel-image-3 ">
          <div class="container">
            <div class="carousel-caption d-none d-sm-block text-right mb-5">
              <h1 class="display-3">
                Heading Three
              </h1>
              <p class="lead">Lorem, ipsum dolor sit amet consectetur adipisicing elit. Doloribus nostrum excepturi
                repellendus quos provident sit! Odio odit quo voluptatum aperiam.</p>
              <a href="#" class="btn btn-success btn-lg">Learn More</a>
            </div>
          </div>
        </div>
      </div>

      <a href="#myCarousel" class="carousel-control-prev" data-slide="prev">
        <span class="carousel-control-prev-icon"></span>
      </a>
      <a href="#myCarousel" class="carousel-control-next" data-slide="next">
        <span class="carousel-control-next-icon"></span>
      </a>
    </div>
  </section>

  <script src="http://code.jquery.com/jquery-3.3.1.min.js"
    integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
    integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous">
  </script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
    integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous">
  </script>

</body>

</html>

最佳答案

您只需为滑块指定一个高度-默认为0像素高。 :-)

正如您在下面看到的,我刚刚添加了400px的min-height(您可以将其设置为任意值),并且还设置了随机背景,以便您可以看到白色文本(因为它不是出现在您的示例中,但滑块实际上在后台运行。



.carousel-item {
  min-height: 400px;
  background-image: url('https://picsum.photos/1200/400');
}

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
    integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css"
    integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
  <link rel="stylesheet" href="/css/style.css">
  <title>Title</title>
</head>

<body>

  <!-- Showcase Slider-->

  <section class="showcase">
    <div id="myCarousel" class="carousel slide" data-ride="carousel">
      <ol class="carousel-indicators">
        <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
        <li data-target="#myCarousel" data-slide-to="1"></li>
        <li data-target="#myCarousel" data-slide-to="2"></li>
      </ol>
      <div class="carousel-inner">
        <div class="carousel-item carousel-image-1 active">
          <div class="container">
            <div class="carousel-caption d-none d-sm-block text-right mb-5">
              <h1 class="display-3">
                Heading One
              </h1>
              <p class="lead">Lorem, ipsum dolor sit amet consectetur adipisicing elit. Doloribus nostrum excepturi
                repellendus quos provident sit! Odio odit quo voluptatum aperiam.</p>
              <a href="#" class="btn btn-danger btn-lg">Sign Up Now</a>
            </div>
          </div>
        </div>

        <div class="carousel-item carousel-image-2 ">
          <div class="container">
            <div class="carousel-caption d-none d-sm-block  mb-5">
              <h1 class="display-3">
                Heading Two
              </h1>
              <p class="lead">Lorem, ipsum dolor sit amet consectetur adipisicing elit. Doloribus nostrum excepturi
                repellendus quos provident sit! Odio odit quo voluptatum aperiam.</p>
              <a href="#" class="btn btn-primary btn-lg">Learn More</a>
            </div>
          </div>
        </div>

        <div class="carousel-item carousel-image-3 ">
          <div class="container">
            <div class="carousel-caption d-none d-sm-block text-right mb-5">
              <h1 class="display-3">
                Heading Three
              </h1>
              <p class="lead">Lorem, ipsum dolor sit amet consectetur adipisicing elit. Doloribus nostrum excepturi
                repellendus quos provident sit! Odio odit quo voluptatum aperiam.</p>
              <a href="#" class="btn btn-success btn-lg">Learn More</a>
            </div>
          </div>
        </div>
      </div>

      <a href="#myCarousel" class="carousel-control-prev" data-slide="prev">
        <span class="carousel-control-prev-icon"></span>
      </a>
      <a href="#myCarousel" class="carousel-control-next" data-slide="next">
        <span class="carousel-control-next-icon"></span>
      </a>
    </div>
  </section>

  <script src="http://code.jquery.com/jquery-3.3.1.min.js"
    integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
    integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous">
  </script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
    integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous">
  </script>

</body>

</html>

关于html - 当单击控件时,轮播效果不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55456283/

10-13 01:42