【问题标题】:Infinite carousel with Twitter Bootstrap带有 Twitter Bootstrap 的无限轮播
【发布时间】:2014-12-04 10:42:00
【问题描述】:

我有一个轮播,我正在使用 Twitter Bootstrap。

我必须在里面装 5 件物品。我举个简单的例子:

<div id="carolsel" class="carousel slide" data-ride="carousel">
     <div class="carousel-inner">
          <div class="item active">
               <div class="col-lg-3">
                    <p>Content</p>
               </div>
               <div class="col-lg-3">
                    <p>Content</p>
               </div>
               <div class="col-lg-3">
                    <p>Content</p>
               </div>
               <div class="col-lg-3">
                    <p>Content</p>
               </div>
          </div>
          <div class="item">
               <div class="col-lg-3">
                    <p>Content</p>
               </div>
          </div>
     </div>
</div>

它显示 4 个项目,然后单独显示一个项目。 有一种方法可以制作无限轮播,让第一个内容出现在最后一个内容之后?

item div 由 foreach 动态创建,内容来自 MYSQL 数据库。

【问题讨论】:

标签: jquery css twitter-bootstrap


【解决方案1】:

Bootstrap 3 轮播的默认行为是以无限方式循环浏览项目。请参阅 Bootstrap 3 文档中的第一个轮播示例:Bootstrap 3 documentation - see carousel section

从 carousel 的文档中,在 Options 部分中,控制循环行为的设置名为 wrap ,默认值设置为 true 以便它连续循环。

在下面的示例 HTML 中(来自文档),请注意每个内容(图像等)都将放在自己的 div 容器中:

    <div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
  <!-- Indicators -->
  <ol class="carousel-indicators">
    <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
    <li data-target="#carousel-example-generic" data-slide-to="1"></li>
    <li data-target="#carousel-example-generic" data-slide-to="2"></li>
  </ol>

  <!-- Wrapper for slides -->
  <div class="carousel-inner">
    <div class="item active">
      <img src="..." alt="...">
      <div class="carousel-caption">
        ...
      </div>
    </div>
    <div class="item">
      <img src="..." alt="...">
      <div class="carousel-caption">
        ...
      </div>
    </div>
    ...
  </div>

  <!-- Controls -->
  <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left"></span>
  </a>
  <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right"></span>
  </a>
</div>

【讨论】:

  • 这样做,我必须将每个内容放在一个item div 中?
  • 是的,并编辑了原始答案以反映说明这一点的 HTML 示例。
  • 是的,它奏效了。但我想显示 4 个内容,然后在显示 1 个最后一个内容和前 3 个其他内容之后从 4 个首字母开始。
  • 不确定我是否遵循您要执行的操作。在同一个容器中显示 1、2、3、4、5,然后是 1+2+3?
  • 是的。 1 2 3 4 - 幻灯片 - 5 1 2 3 - 幻灯片 - 4 5 1 2 - 幻灯片 - 3 4 5 1 并继续。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-13
  • 2012-05-26
  • 2014-07-10
  • 1970-01-01
相关资源
最近更新 更多