swiper-分页标签内加time时间进度条

本文介绍了如何使用Swiper库创建一个响应式的轮播图,以及如何改进其样式(如颜色和动画)以提高视觉吸引力。着重提到了CSS和JavaScript在实现个性化设计中的作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

效果图-样式颜色很丑,需要的请自行优化
在这里插入图片描述


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

<head>
  <meta charset="utf-8" />
  <title>Swiper demo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1" />
  <!-- Link Swiper's CSS -->
  <link rel="stylesheet" href="assets/styles/other/swiper-bundle.min.css" />

  <!-- Demo styles -->
  <style>
    html,
    body {
      position: relative;
      height: 100%;
    }

    body {
      background: #eee;
      font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
      font-size: 14px;
      color: #000;
      margin: 0;
      padding: 0;
    }

    .swiper {
      width: 100%;
      height: 100%;
    }

    .swiper-slide {
      text-align: center;
      font-size: 18px;
      background: #fff;
      display: flex;
      justify-content: center;
      align-items: center;
    }

    .swiper-slide img {
      display: block;
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
    .swiper-slide::before{
        content: '';
        left: 0;
        top: 0;
        width: 100%;
        height: 2px;
        background-color: #000;
        position: absolute;
        transform: scaleX(0);
        transform-origin: left;
        z-index: 3;
        transition-timing-function: linear;
    }
    .swiper-pagination-bullet{
        background-color: transparent;
        opacity: 1;
        margin: 0 6px !important;
        width: 60px;
        height: 9px;
        position: relative;
        outline: none;
        vertical-align: middle;
    }
    .swiper-pagination-bullet span{
        width: 60px;
        height: 3px;
        background-color: #ccc;
        display: block;
        margin-top: 3px;
    }
    .swiper-pagination-bullet i{
        background-color: #000;
        height: 3px;
        width: 60px;
        position: absolute;
        top: 4px;
        transform: scaleX(0);
        transform-origin: left;
        z-index: 3;
        transition-timing-function: linear;
    }
    .swiper-pagination-bullet-active i{
        animation: middle 5s forwards;//与autoplay delay的时间保持一致
    }
    @keyframes middle{
        0%{
            transform: scaleX(0);
            left: 0;
        }
        100%{
            transform: scaleX(1);
            left: 0;
        }
    }
  </style>
</head>

<body>
  <div class="swiper mySwiper">
    <div class="swiper-wrapper">
      <div class="swiper-slide">Slide 1</div>
      <div class="swiper-slide">Slide 2</div>
      <div class="swiper-slide">Slide 3</div>
      <div class="swiper-slide">Slide 4</div>
      <div class="swiper-slide">Slide 5</div>
      <div class="swiper-slide">Slide 6</div>
      <div class="swiper-slide">Slide 7</div>
      <div class="swiper-slide">Slide 8</div>
      <div class="swiper-slide">Slide 9</div>
    </div>
    <div class="swiper-pagination"></div>
  </div>

  <!-- Swiper JS -->
  <script src="assets/scripts/other/swiper-bundle.min.js"></script>

  <!-- Initialize Swiper -->
  <script>
    var swiper = new Swiper(".mySwiper", {
      autoplay: {
        delay: 5000,
      },
      pagination: {
        el: ".swiper-pagination",
        clickable: true,
        renderBullet: function (index, className) {
            return '<div class="' + className + '"><span></span><i></i></div>';
        },
      },
    });
  </script>
</body>

</html>


要实现跑马灯效果,你可以使用Swiper Web组件的swiper-container标签结合一些配置选项。下面是一个示例代码: ```html <!DOCTYPE html> <html> <head> <!-- 引入SwiperCSS文件 --> <link rel="stylesheet" href="https://unpkg.com/swiper/swiper-bundle.min.css"> </head> <body> <!-- 创建一个swiper容器 --> <div class="swiper-container"> <!-- 创建一个swiper-wrapper容器,用于包裹轮播项 --> <div class="swiper-wrapper"> <!-- 创建多个swiper-slide,每个slide代表一个轮播项 --> <div class="swiper-slide">Slide 1</div> <div class="swiper-slide">Slide 2</div> <div class="swiper-slide">Slide 3</div> <!-- 可以根据需求添更多的轮播项 --> </div> </div> <!-- 引入Swiper的JS文件 --> <script src="https://unpkg.com/swiper/swiper-bundle.min.js"></script> <script> // 初始化Swiper实例 var swiper = new Swiper('.swiper-container', { // 设置轮播方向为水平 direction: 'horizontal', // 设置循环轮播 loop: true, // 设置自动播放 autoplay: { delay: 2000, // 延迟时间,单位为毫秒 disableOnInteraction: false, // 用户操作后是否禁止自动播放 }, }); </script> </body> </html> ``` 上述代码中,我们使用了Swiper Web组件的swiper-container标签作为轮播容器,swiper-wrapper标签包裹轮播项,每个轮播项使用swiper-slide标签表示。通过配置选项,我们设置了水平方向的循环轮播,并启用了自动播放功能。 你可以根据自己的需求修改轮播项的内容和样式,以及调整配置选项来实现所需的跑马灯效果
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值