首页 > 其他分享 >bootstrap之carousel轮播图自定义分页器

bootstrap之carousel轮播图自定义分页器

时间:2023-04-03 14:55:33浏览次数:46  
标签:function const 轮播 自定义 bootstrap carousel group page

最近要开发一个轮播图的看板页面,试用下bootstrap的轮播图组件,因为分页器的部分需要自定义(文字过长需要放到轮播图区域的外面),使用 List group组件作为轮播图的分页器放在左边。 

<!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.0" />
    <title>Document</title>
    <link href="./plugins/bootstrap-5.1.3/css/bootstrap.min.css" rel="stylesheet" />
    <script src="./plugins/jquery/jquery-3.3.1.js"></script>
    <script src="./plugins/bootstrap-5.1.3/js/bootstrap.bundle.min.js"></script>
    <style>
      .carousel-item {
        height: 400px;
        border: 1px silver solid;
      }
      .list-group {
        height: 400px;
        overflow-y: scroll;
        transition: scrollTop 2s ease-out;
      }
    </style>
  </head>
  <body>
    <div class="container-fluid">
      <div class="row g-2 mt-3">
        <div class="col-2">
          <div class="list-group" id="listGroup">
            <div data-bs-target="#carouselExample" data-bs-slide-to="0" class="list-group-item active">Item0</div>
            <div data-bs-target="#carouselExample" data-bs-slide-to="1" class="list-group-item">Item1</div>
            <div data-bs-target="#carouselExample" data-bs-slide-to="2" class="list-group-item">Item2</div>
            <div data-bs-target="#carouselExample" data-bs-slide-to="3" class="list-group-item">Item3</div>
            <div data-bs-target="#carouselExample" data-bs-slide-to="4" class="list-group-item">Item4</div>
            <div data-bs-target="#carouselExample" data-bs-slide-to="5" class="list-group-item">Item5</div>
            <div data-bs-target="#carouselExample" data-bs-slide-to="6" class="list-group-item">Item6</div>
            <div data-bs-target="#carouselExample" data-bs-slide-to="7" class="list-group-item">Item7</div>
            <div data-bs-target="#carouselExample" data-bs-slide-to="8" class="list-group-item">Item8</div>
            <div data-bs-target="#carouselExample" data-bs-slide-to="9" class="list-group-item">Item9</div>
            <div data-bs-target="#carouselExample" data-bs-slide-to="10" class="list-group-item">Item10</div>
            <div data-bs-target="#carouselExample" data-bs-slide-to="11" class="list-group-item">Item11</div>
            <div data-bs-target="#carouselExample" data-bs-slide-to="12" class="list-group-item">Item12</div>
            <div data-bs-target="#carouselExample" data-bs-slide-to="13" class="list-group-item">Item13</div>
            <div data-bs-target="#carouselExample" data-bs-slide-to="14" class="list-group-item">Item14</div>
            <div data-bs-target="#carouselExample" data-bs-slide-to="15" class="list-group-item">Item15</div>
            <div data-bs-target="#carouselExample" data-bs-slide-to="16" class="list-group-item">Item16</div>
            <div data-bs-target="#carouselExample" data-bs-slide-to="17" class="list-group-item">Item17</div>
            <div data-bs-target="#carouselExample" data-bs-slide-to="18" class="list-group-item">Item18</div>
            <div data-bs-target="#carouselExample" data-bs-slide-to="19" class="list-group-item">Item19</div>
            <div data-bs-target="#carouselExample" data-bs-slide-to="20" class="list-group-item">Item20</div>
            <div data-bs-target="#carouselExample" data-bs-slide-to="21" class="list-group-item">Item21</div>
            <div data-bs-target="#carouselExample" data-bs-slide-to="22" class="list-group-item">Item22</div>
            <div data-bs-target="#carouselExample" data-bs-slide-to="23" class="list-group-item">Item23</div>
            <div data-bs-target="#carouselExample" data-bs-slide-to="24" class="list-group-item">Item24</div>
            <div data-bs-target="#carouselExample" data-bs-slide-to="25" class="list-group-item">Item25</div>
            <div data-bs-target="#carouselExample" data-bs-slide-to="26" class="list-group-item">Item26</div>
            <div data-bs-target="#carouselExample" data-bs-slide-to="27" class="list-group-item">Item27</div>
            <div data-bs-target="#carouselExample" data-bs-slide-to="28" class="list-group-item">Item28</div>
            <div data-bs-target="#carouselExample" data-bs-slide-to="29" class="list-group-item">Item29</div>
            <div data-bs-target="#carouselExample" data-bs-slide-to="30" class="list-group-item">Item30</div>
            <div data-bs-target="#carouselExample" data-bs-slide-to="31" class="list-group-item">Item31</div>
            <div data-bs-target="#carouselExample" data-bs-slide-to="32" class="list-group-item">Item32</div>
            <div data-bs-target="#carouselExample" data-bs-slide-to="33" class="list-group-item">Item33</div>
            <div data-bs-target="#carouselExample" data-bs-slide-to="34" class="list-group-item">Item34</div>
          </div>
        </div>
        <div class="col-10">
          <div id="carouselExample" class="carousel slide carousel-fade" data-bs-ride="carousel" data-bs-interval="2000" data-bs-touch="false">
            <div class="carousel-inner">
              <div class="carousel-item active">Item0</div>
              <div class="carousel-item">Item1</div>
              <div class="carousel-item">Item2</div>
              <div class="carousel-item">Item3</div>
              <div class="carousel-item">Item4</div>
              <div class="carousel-item">Item5</div>
              <div class="carousel-item">Item6</div>
              <div class="carousel-item">Item7</div>
              <div class="carousel-item">Item8</div>
              <div class="carousel-item">Item9</div>
              <div class="carousel-item">Item10</div>
              <div class="carousel-item">Item11</div>
              <div class="carousel-item">Item12</div>
              <div class="carousel-item">Item13</div>
              <div class="carousel-item">Item14</div>
              <div class="carousel-item">Item15</div>
              <div class="carousel-item">Item16</div>
              <div class="carousel-item">Item17</div>
              <div class="carousel-item">Item18</div>
              <div class="carousel-item">Item19</div>
              <div class="carousel-item">Item20</div>
              <div class="carousel-item">Item21</div>
              <div class="carousel-item">Item22</div>
              <div class="carousel-item">Item23</div>
              <div class="carousel-item">Item24</div>
              <div class="carousel-item">Item25</div>
              <div class="carousel-item">Item26</div>
              <div class="carousel-item">Item27</div>
              <div class="carousel-item">Item28</div>
              <div class="carousel-item">Item29</div>
              <div class="carousel-item">Item30</div>
              <div class="carousel-item">Item31</div>
              <div class="carousel-item">Item32</div>
              <div class="carousel-item">Item33</div>
              <div class="carousel-item">Item34</div>
            </div>
            <button class="carousel-control-prev" type="button" data-bs-target="#carouselExample" data-bs-slide="prev">
              <span class="carousel-control-prev-icon" aria-hidden="true"></span>
              <span class="visually-hidden">Previous</span>
            </button>
            <button class="carousel-control-next" type="button" data-bs-target="#carouselExample" data-bs-slide="next">
              <span class="carousel-control-next-icon" aria-hidden="true"></span>
              <span class="visually-hidden">Next</span>
            </button>
          </div>
        </div>
      </div>
      <div class="row mt-3">
        <label> <input class="form-check-input" type="checkbox" id="checkbox" value="" />stop </label>
      </div>
    </div>
  </body>
  <script>
    const myCarousel = document.getElementById("carouselExample");
    const carousel = new bootstrap.Carousel("#carouselExample");
    const perPage = 10;
    const size = 35;
    const perHeight = 41;
    const listGroup = document.getElementById("listGroup");

    myCarousel.addEventListener("slide.bs.carousel", (event) => {
      $(".list-group-item").eq(event.to).addClass("active").siblings().removeClass("active");
    });
    myCarousel.onmouseover = function () {
      clearInterval(timer);
    };
    myCarousel.onmouseout = function () {
      timer = setInterval(page, 2000);
    };
    $(".list-group-item").click(function (event) {
      $(this).addClass("active").siblings().removeClass("active");
    });
    $(".carousel-control-prev").click(function () {
      page();
    });
    $(".carousel-control-next").click(function () {
      page();
    });
    $("#checkbox").on("click", function () {
      if ($(this).is(":checked")) {
        clearInterval(timer);
        carousel.pause();
      } else {
        timer = setInterval(page, 2000);
        carousel.cycle();
      }
    });

    function page() {
      const index = $(".list-group-item.active").index();
      const n = Math.floor(size / perPage);
      for (let i = 0; i <= n; i++) {
        if (index >= i * perPage && index < (i + 1) * perPage) {
          listGroup.scrollTop = i * perPage * perHeight;
        }
      }
    }

    let timer = setInterval(page, 2000);
  </script>
</html>

  

 

标签:function,const,轮播,自定义,bootstrap,carousel,group,page
From: https://www.cnblogs.com/caroline2016/p/17283042.html

相关文章

  • 直播平台开发,小程序自定义搜索标题栏
    直播平台开发,小程序自定义搜索标题栏一:需求把微信小程序标题栏处变成搜索栏。自定义返回上级页面。二:需求分析首先要把小程序标题栏设置为可自定义。然后计算原标题栏的高度组成结构。根据计算高度设置搜索框和返回按钮的布局。最后进行代码功能实现。三:功能实现1:设置标......
  • vue3 ant-Design-vue提交按钮放在表单外提交,自定义提交按钮
    <template><a-formref="urlEditRef":model="urlEditInfo"name="urlEdit_rule"layout="vertical"><a-form-itemlabel="跳转链接"name="longUrl":rules=&qu......
  • 【pytest】 pytest自定义标记 PytestUnknownMarkWarning处理方式
    未注册标记会出现warningssummary-- PytestUnknownMarkWarningPytestUnknownMarkWarning:Unknownpytest.mark.demo-isthisatypo?Youcanregistercustommarkstoavoidthiswarning-fordetails,seehttps://docs.pytest.org/en/stable/how-to/mark.html@......
  • Power BI App Souce所有的自定义视觉对象打包
    PowerBIAppSouce所有的自定义视觉对象提取PowerBI最全487个官网自定义视觉对象提取[Date:2023/04/03]官网地址:BusinessApps–MicrosoftAppSourcePowerBI自定义视觉对象的PBIVIZ和示例PBIX文件:   下载地址:PBICustomVisuals.zip ......
  • Visual Studio Code 使用插件 Markdown Preview Enhanced 导出文档时和自定义设置的预
    首先,我这里的预览主题设置为了vue.css  但是导出时并不正常,根本不是vue.css这个主题的外观。所以需要在插件中配置如下内容:以下配置项都在VSCode的Extension->MarkdownPreviewEnhanced中找到 1.CodeBlockTheme配置成预览一样  2.PrintBackground......
  • 【微信小程序-原生开发】实用教程14 - 列表的分页加载,触底加载更多(含无更多数据的提醒
    此页可在动态列表的基础上完善,也可以单独学习【微信小程序-原生开发】实用教程10-动态列表的新增、修改、删除效果预览核心技术列表的分页加载skip跳跃到指定下标开始查询limit限制返回的数据数量(云数据库最多20条/次,云函数最多100条/次)skip配合limit使用,便能实现分页啦!.ski......
  • Element UI 【表格合计】el-table 实战范例 -- 添加单位,自定义计算逻辑
    需求描述末尾合计行的需求如下:第1列显示“合计”无法求和的列,显示“——”可以求和的列,显示求和结果,并添加对应的单位命中率列的合计逻辑为:总命中数/总射击次数代码实现要点详见代码中的备注<template><divclass="tableBox"><el-table:data="tableData"bo......
  • vue3 - 引入自定义插件的组件的具体写法
    1.背景我的这一篇随笔详细讲解组件怎么制作与引入使用【vue3-在单独的项目制作自定义组件插件,支持vite【前提不要使用webpack专属语法】,并引入插件-心得-岑惜-博客园(cnblogs.com)】但在局部引入组件时,eslint红色警告   引用名言:“又不是不能用==”强迫症看着实......
  • 微信小程序自定义封装组件-showModal
    封装一个组件这里由于最近使用微信小程序居多,所以着重写的是小程序的,但是万变不离其宗,组件实现思路其实都差不多的微信小程序开发中官方自带的wx.showModal,这个弹窗API有时候并不能满足我们的弹窗效果,所以往往需要自定义modal组件。下面我们进行一个自定义modal弹窗组件的开发,并......
  • vue3 directive自定义指令
    importstorefrom'../store'//新建jsexportdefault{install(app){//权限控制,没有相关的权限,则删除模块app.directive('permission',{mounted(el,val){if(el&&!store.state.rule.includes(val.valu......