做响应时的轮播缩略图问题

时间:2018-01-06 10:01:49

标签: javascript jquery html css twitter-bootstrap

我正在尝试使用bootstrap创建响应式轮播缩略图滑块。在桌面上没有问题。一切都好。但是当我调整移动显示窗口的大小时,旋转木马会在垂直方向上分解列。

我想一次显示一个缩略图,并希望一个接一个地显示下一个缩略图。

我希望在移动版enter image description here

中使用此功能

以下是我的工作演示

.collaborators {
  background: #0492da;
  font-family: 'Work Sans', sans-serif;
  color: #fff;
  padding: 50px 0;
  position: relative;
  z-index: 2;
}

.collaborators h1 {
  font-size: 50px;
  font-weight: 300;
}

.text1 {
  font-size: 20px;
}

.carousel-control {
  width: auto;
}
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />

<section class="collaborators">
  <div class="container">
    <div class="row">
      <div class="col-xs-12 text-center">
        <h1>Collaborators</h1>
        <p class="text1">Based in the Ottawa/Gatineau area, Lead Action specializes primarily in Leadership Development.</p>
      </div>

      <div class="col-xs-12">
        <div id="collaborators" class="carousel slide" data-ride="carousel">
          <ol class="carousel-indicators">
            <li data-target="#collaborators" data-slide-to="0" class="active"></li>
            <li data-target="#collaborators" data-slide-to="1"></li>
            <li data-target="#collaborators" data-slide-to="2"></li>
          </ol>

          <div class="carousel-inner" role="listbox">
            <div class="item active">
              <div class="row">
                <div class="col-lg-3">
                  <img src="https://www.w3schools.com/bootstrap/img_chania.jpg" alt="Chania" class="img-responsive">
                  <div class="carousel-caption">
                    <h3>Chania</h3>
                    <p>The atmosphere in Chania has a touch of Florence and Venice.</p>
                  </div>
                </div>
                <div class="col-lg-3">
                  <img src="https://www.w3schools.com/bootstrap/img_chania.jpg" alt="Chania" class="img-responsive">
                  <div class="carousel-caption">
                    <h3>Chania</h3>
                    <p>The atmosphere in Chania has a touch of Florence and Venice.</p>
                  </div>
                </div>
                <div class="col-lg-3">
                  <img src="https://www.w3schools.com/bootstrap/img_chania.jpg" alt="Chania" class="img-responsive">
                  <div class="carousel-caption">
                    <h3>Chania</h3>
                    <p>The atmosphere in Chania has a touch of Florence and Venice.</p>
                  </div>
                </div>
                <div class="col-lg-3">
                  <img src="https://www.w3schools.com/bootstrap/img_chania.jpg" alt="Chania" class="img-responsive">
                  <div class="carousel-caption">
                    <h3>Chania</h3>
                    <p>The atmosphere in Chania has a touch of Florence and Venice.</p>
                  </div>
                </div>
              </div>
            </div>

            <div class="item">
              <div class="row">
                <div class="col-lg-3">
                  <img src="https://www.w3schools.com/bootstrap/img_chania.jpg" alt="Chania" class="img-responsive">
                  <div class="carousel-caption">
                    <h3>Chania</h3>
                    <p>The atmosphere in Chania has a touch of Florence and Venice.</p>
                  </div>
                </div>
                <div class="col-lg-3">
                  <img src="https://www.w3schools.com/bootstrap/img_chania.jpg" alt="Chania" class="img-responsive">
                  <div class="carousel-caption">
                    <h3>Chania</h3>
                    <p>The atmosphere in Chania has a touch of Florence and Venice.</p>
                  </div>
                </div>
                <div class="col-lg-3">
                  <img src="https://www.w3schools.com/bootstrap/img_chania.jpg" alt="Chania" class="img-responsive">
                  <div class="carousel-caption">
                    <h3>Chania</h3>
                    <p>The atmosphere in Chania has a touch of Florence and Venice.</p>
                  </div>
                </div>
                <div class="col-lg-3">
                  <img src="https://www.w3schools.com/bootstrap/img_chania.jpg" alt="Chania" class="img-responsive">
                  <div class="carousel-caption">
                    <h3>Chania</h3>
                    <p>The atmosphere in Chania has a touch of Florence and Venice.</p>
                  </div>
                </div>
              </div>
            </div>

            <div class="item">
              <div class="row">
                <div class="col-lg-3">
                  <img src="https://www.w3schools.com/bootstrap/img_chania.jpg" alt="Chania" class="img-responsive">
                  <div class="carousel-caption">
                    <h3>Chania</h3>
                    <p>The atmosphere in Chania has a touch of Florence and Venice.</p>
                  </div>
                </div>
                <div class="col-lg-3">
                  <img src="https://www.w3schools.com/bootstrap/img_chania.jpg" alt="Chania" class="img-responsive">
                  <div class="carousel-caption">
                    <h3>Chania</h3>
                    <p>The atmosphere in Chania has a touch of Florence and Venice.</p>
                  </div>
                </div>
                <div class="col-lg-3">
                  <img src="https://www.w3schools.com/bootstrap/img_chania.jpg" alt="Chania" class="img-responsive">
                  <div class="carousel-caption">
                    <h3>Chania</h3>
                    <p>The atmosphere in Chania has a touch of Florence and Venice.</p>
                  </div>
                </div>
                <div class="col-lg-3">
                  <img src="https://www.w3schools.com/bootstrap/img_chania.jpg" alt="Chania" class="img-responsive">
                  <div class="carousel-caption">
                    <h3>Chania</h3>
                    <p>The atmosphere in Chania has a touch of Florence and Venice.</p>
                  </div>
                </div>
              </div>
            </div>

          </div>

          <a class="left carousel-control" href="#collaborators" role="button" data-slide="prev">
            <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
            <span class="sr-only">Previous</span>
          </a>
          <a class="right carousel-control" href="#collaborators" role="button" data-slide="next">
            <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
            <span class="sr-only">Next</span>
          </a>
        </div>
      </div>

    </div>
  </div>
</section>

1 个答案:

答案 0 :(得分:1)

尝试此代码段,希望这是您所期望的。如果您有任何疑问,可以在评论部分询问。

我还提到了w3schools bootstrap carousel。

.collaborators {
  background: #0492da;
  font-family: 'Work Sans', sans-serif;
  color: #fff;
  padding: 50px 0;
  position: relative;
  z-index: 2;
}

.collaborators h2 {
  font-size: 50px;
  font-weight: 300;
  text-align: center;
}

.text1 {
  font-size: 20px;
  text-align: center;
}

.carousel-control {
  width: auto;
}
<!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.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>

<body>

  <div class="container">
    <div class="collaborators">
      <h2>Collaborators</h2>
      <p class="text1">Based in the Ottawa/Gatineau area, Lead Action specializes primarily in Leadership Development.</p>
      <div class="col-xs-12 text-center">

      </div>
      <div id="myCarousel" class="carousel slide" data-ride="carousel">
        <!-- Indicators -->
        <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>

        <!-- Wrapper for slides -->
        <div class="carousel-inner">
          <div class="item active">
            <img src="https://www.w3schools.com/bootstrap/img_chania.jpg" alt="Los Angeles" style="width:100%;">
          </div>

          <div class="item">
            <img src="https://www.w3schools.com/bootstrap/img_chania.jpg" alt="Chicago" style="width:100%;">
          </div>

          <div class="item">
            <img src="https://www.w3schools.com/bootstrap/img_chania.jpg" alt="New york" style="width:100%;">
          </div>
        </div>

        <!-- Left and right controls -->
        <a class="left carousel-control" href="#myCarousel" data-slide="prev">
          <span class="glyphicon glyphicon-chevron-left"></span>
          <span class="sr-only">Previous</span>
        </a>
        <a class="right carousel-control" href="#myCarousel" data-slide="next">
          <span class="glyphicon glyphicon-chevron-right"></span>
          <span class="sr-only">Next</span>
        </a>
      </div>
    </div>
  </div>

</body>

</html>

  

编辑版

每个轮播项目4张图片

.collaborators {
  background: #0492da;
  font-family: 'Work Sans', sans-serif;
  color: #fff;
  padding: 50px 0;
  position: relative;
  z-index: 2;
}

.collaborators h2 {
  font-size: 50px;
  font-weight: 300;
  text-align: center;
}

.text1 {
  font-size: 20px;
  text-align: center;
}

.carousel-control {
  width: auto;
}
<!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.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>

<body>
<div class="collaborators">
      <h2>Collaborators</h2>
      <p class="text1">Based in the Ottawa/Gatineau area, Lead Action specializes primarily in Leadership Development.</p>
  <div class="col-md-12 text-center">
  </div>
  <div class="col-md-6 col-md-offset-3">
    <div class="carousel slide" id="myCarousel">
      <div class="carousel-inner">
        <div class="item active">
          <div class="row">
            <div class="col-xs-3">
              <a href="#"><img src="https://www.w3schools.com/bootstrap/img_chania.jpg" class="img-responsive"></a>
            </div>
            <div class="col-xs-3">
              <a href="#"><img src="https://www.w3schools.com/bootstrap/img_chania.jpg" class="img-responsive"></a>
            </div>
            <div class="col-xs-3">
              <a href="#"><img src="https://www.w3schools.com/bootstrap/img_chania.jpg" class="img-responsive"></a>
            </div>
            <div class="col-xs-3">
              <a href="#"><img src="https://www.w3schools.com/bootstrap/img_chania.jpg" class="img-responsive"></a>
            </div>
          </div>
        </div>
        <div class="item">
          <div class="row">
            <div class="col-xs-3">
              <a href="#"><img src="https://www.w3schools.com/bootstrap/img_chania.jpg" class="img-responsive"></a>
            </div>
            <div class="col-xs-3">
              <a href="#"><img src="https://www.w3schools.com/bootstrap/img_chania.jpg" class="img-responsive"></a>
            </div>
            <div class="col-xs-3">
              <a href="#"><img src="https://www.w3schools.com/bootstrap/img_chania.jpg" class="img-responsive"></a>
            </div>
            <div class="col-xs-3">
              <a href="#"><img src="https://www.w3schools.com/bootstrap/img_chania.jpg" class="img-responsive"></a>
            </div>
          </div>
        </div>
      </div>
      <a class="left carousel-control" href="#myCarousel" data-slide="prev"><i class="glyphicon glyphicon-chevron-left"></i></a>
      <a class="right carousel-control" href="#myCarousel" data-slide="next"><i class="glyphicon glyphicon-chevron-right"></i></a>
    </div>
    </div>
  </div>
</body>

</html>