Bootstrap 轮播显示下一张和上一张图像

2024-02-27

引导程序轮播是否可扩展以在滑块中显示下一个和上一个图像?

    <div id="carousel-example-generic" class="carousel slide" data-ride="carousel" data-interval="false">
      <!-- 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>
      </ol>

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

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

我的轮播现在看起来像这样,如何将上一张和下一张图像添加到当前活动的幻灯片中?


Bootstrap 4 的解决方案

字幕在 768 像素宽或更大的屏幕上可见。

https://codepen.io/glebkema/pen/daLzpL https://codepen.io/glebkema/pen/daLzpL

$('.carousel-item', '.multi-item-carousel').each(function(){
  var next = $(this).next();
  if (! next.length) {
    next = $(this).siblings(':first');
  }
  next.children(':first-child').clone().appendTo($(this));
}).each(function(){
  var prev = $(this).prev();
  if (! prev.length) {
    prev = $(this).siblings(':last');
  }
  prev.children(':nth-last-child(2)').clone().prependTo($(this));
});
.multi-item-carousel {
  overflow: hidden;
}
.multi-item-carousel .carousel-indicators {
  margin-right: 25%;
  margin-left: 25%;
}
.multi-item-carousel .carousel-control-prev,
.multi-item-carousel .carousel-control-next {
  background: rgba(255, 255, 255, 0.3);
  width: 25%;
  z-index: 11; /* .carousel-caption has z-index 10 */
}
.multi-item-carousel .carousel-inner {
  width: 150%;
  left: -25%;
}
.multi-item-carousel .carousel-item-next:not(.carousel-item-left),
.multi-item-carousel .carousel-item-right.active {
  -webkit-transform: translate3d(33%, 0, 0);
  transform: translate3d(33%, 0, 0);
}
.multi-item-carousel .carousel-item-prev:not(.carousel-item-right),
.multi-item-carousel .carousel-item-left.active {
  -webkit-transform: translate3d(-33%, 0, 0);
  transform: translate3d(-33%, 0, 0);
}
.multi-item-carousel .item__third {
  float: left;
  position: relative;
  width: 33.33333333%;
}
<div class="bd-example">
  <div id="carouselExampleCaptions" class="carousel slide multi-item-carousel" data-ride="carousel">

    <ol class="carousel-indicators">
      <li data-target="#carouselExampleCaptions" data-slide-to="0" class="active"></li>
      <li data-target="#carouselExampleCaptions" data-slide-to="1"></li>
      <li data-target="#carouselExampleCaptions" data-slide-to="2"></li>
    </ol>

    <div class="carousel-inner">
      <div class="carousel-item active">
        <div class="item__third">
          <img src="https://via.placeholder.com/900x300/c69/f9c/?text=1" class="d-block w-100" alt="">
          <div class="carousel-caption d-none d-md-block">
            <h5>First slide label</h5>
            <p>Nulla vitae elit libero, a pharetra augue mollis interdum.</p>
          </div>
        </div>
      </div>
      <div class="carousel-item">
        <div class="item__third">
          <img src="https://via.placeholder.com/900x300/9c6/cf9/?text=2" class="d-block w-100" alt="">
          <div class="carousel-caption d-none d-md-block">
            <h5>Second slide label</h5>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
          </div>
        </div>
      </div>
      <div class="carousel-item">
        <div class="item__third">
          <img src="https://via.placeholder.com/900x300/69c/9cf/?text=3" class="d-block w-100" alt="">
          <div class="carousel-caption d-none d-md-block">
            <h5>Third slide label</h5>
            <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur.</p>
          </div>
        </div>
      </div>
    </div>

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

  </div>
</div>

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Bootstrap 轮播显示下一张和上一张图像 的相关文章

随机推荐

  • 在 Talend 中加载一组文件的策略

    我想知道在 Talend 中解决以下问题的最佳策略是什么 我需要从存储在名称类似于 SAMPLE1 DAT SAMPLE2 DAT SAMPLEX DAT 的目录中的一组分隔文件中加载数据 目标将是 MySQL 数据库中的一个表 我必须立即
  • 内联复选框ajax修改数字

    我有一个像这样的 html 例如 li li
  • Keycloak/Wildfly 如何将所有控制台日志配置为 JSON 格式

    我正在使用官方 Keycloak 图像并尝试为控制台日志设置 JSON 格式 如下所示 启动 cli embed server server config standalone ha xml std out echo subsystem l
  • 导轨 3;活动记录;在哪里;数据库中两列之间的 NOT EQUAL 条件比较

    有没有某种方法可以使用比较数据库中的两列where 比如说 我有两列user这告诉我们 出生城市 最喜欢的城市 我想要一个具有不同于 city of birth 的 favourite city 的用户列表 我希望这样的事情能够奏效 use
  • 模糊图像的阈值 - 第 2 部分

    如何对这个模糊图像进行阈值处理以使数字尽可能清晰 In 以前的帖子 https stackoverflow com questions 13391073 adaptive threshold of blurry image 我尝试对模糊图像
  • R中的R图像函数

    我正在使用 R 中附加的图像函数 为了速度 我更喜欢使用它而不是热图 因为我将它用于巨大的矩阵 400000 x 400 我的函数中的问题是调色板的动态范围 在我的例子中它只有蓝色和黄色 我尝试了对 colorramp 线的多次更改 但没有
  • 获取不包含 DOCTYPE、HTML、HEAD 和 BODY 标签的 BODY 内容

    我想做的是在 PHP 系统中包含一个 HTML 文件 不是问题 但是由于各种原因 该 HTML 文件也需要单独使用 所以我需要知道如何剥离 doctype html PHP 上下文中的 head 和 body 标签 如果可能的话 我对 PH
  • 如何使用 Gspread 下载 Google Docs Excel 工作表并在本地访问数据(A1 表示法)?

    我需要通过 Gspread 从 Google Docs 下载 Excel 工作表 然后多次需要读取不同单元格的值 A1 符号 因此 我不能只获取电子表格然后致电val worksheet acell B1 value 因为脚本会因过多的 A
  • 显示 R 和 dplyr 的拟合值

    我有数据框DF 我在用R and dplyr来分析它 DF包含 gt glimpse DF Observations 1244160 Variables Channel int 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  • 将 ExceptionDescribe 转换为字符串

    我需要将 JNI 中 ExceptionDescribe 的输出作为字符串获取 以便之后可以将其写入文件中 而不是直接在命令行上写入 有什么方法或想法可以做到这一点吗 提前致谢 Sami ExceptionOccurred 是第一步 要获取
  • 当区域设置为阿拉伯语时 Android 中的日期格式问题

    我这里有一个严重的问题 我正在构建一个可以在阿拉伯语设备上运行的应用程序 我需要将日期发送到服务器 我使用 Android DatePickerDialog 来获取日期 但日期总是使用阿拉伯语字符发送 并且何时我尝试再次显示它 它给了我无法
  • 使用 JavaScript 计算 A、B、C、D,而不是 0、1、2、3...

    这可能是一个不寻常的请求 但对于我的脚本 我需要一个按字母而不是数字递增的函数 例如 这是一个数字示例 var i 0 while condition window write We are at i i 本质上 我想像 Microsoft
  • Rails 3.1 Devise 如何更改 Flash Message CSS 从通知到成功?

    Rails 3 1 和 Devise 1 5 问题 我使用以下代码在布局中显示 Flash 消息 我想将一些确认消息的 css 类从通知更改为成功 但我不知道在哪里覆盖或更改密钥 因为我不知道它在哪里设置 有人能指出我正确的方向吗 Than
  • Android webapp 中调用 JS 的原生代码

    我正在编写一个Android 网络 应用程序 我不会将应用程序上传到网络 而是在应用程序资源中设置HTML JS 这意味着 GUI 将是 HTML5 我将使用另一个 本机 线程从麦克风读取数据 并希望将 解析后的文本 发送到 HTML5 J
  • Microsoft.AspNetCore.Hosting.Abstractions 清单定义与程序集引用不匹配

    当我运行实体框架核心命令时add migration MyMigrationName在类库中我收到以下错误 无法加载文件或程序集 Microsoft AspNetCore Hosting Abstractions 版本 1 1 1 0 Cu
  • 如何在 C 语言中找到字符串中字符的索引?

    假设我有一个字符串 qwerty 我希望找到的索引位置e其中的人物 在这种情况下 索引将是2 我如何在 C 中做到这一点 我找到了strchr函数 但它返回一个指向字符的指针而不是索引 只需从 strchr 返回的内容中减去字符串地址即可
  • ios UIWebView 中的大量内存泄漏

    为了寻找系统中其他地方的内存泄漏 我创建了一个带有元刷新标签的 20 MB 网页 我们的想法是通过我们的数据路径代码移动大量数据以确认内存稳定性 div style border 1px solid red Content loading
  • 使用单向多对多映射进行删除级联

    我正在使用 Fluent 和 NHibernate 我有两个对象 A 和 B 它们之间具有多对多关系 当 A HasMany B 时 我使用单向多对多映射 B中没有关于A 单向 的参考 这会在数据库中创建第三个表 名为 ABMapping
  • 将日期时间插入 SQLite 数据库

    我试图将时间插入数据库 但是当我打印插入的时间时 它不正确 我在将时间变量插入数据库之前打印了它 它是 12 01 09 149059 我用的时候效果很好strftime但我换了 因为时间已经到了 from datetime import
  • Bootstrap 轮播显示下一张和上一张图像

    引导程序轮播是否可扩展以在滑块中显示下一个和上一个图像 div class carousel slide ol class carousel indicators li class active li li li ol div