Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

swiper.js 实现全屏轮播带视频和图片

作者:战天独尊   发布日期:2026-07-05   浏览:36

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Swiper Fullscreen Carousel with Video and Images</title>
  <link rel="stylesheet" href="https://unpkg.com/swiper/swiper-bundle.min.css" />
  <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-container {
      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 {
      max-width: 100%;
      max-height: 100%;
    }
    .swiper-slide video {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
  </style>
</head>
<body>
  <!-- Swiper -->
  <div class="swiper-container">
    <div class="swiper-wrapper">
      <div class="swiper-slide">
        <img src="https://via.placeholder.com/800x600.png?text=Image+1" alt="Image 1">
      </div>
      <div class="swiper-slide">
        <video autoplay muted loop>
          <source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
        </video>
      </div>
      <div class="swiper-slide">
        <img src="https://via.placeholder.com/800x600.png?text=Image+2" alt="Image 2">
      </div>
    </div>
    <!-- Add Pagination -->
    <div class="swiper-pagination"></div>
    <!-- Add Arrows -->
    <div class="swiper-button-next"></div>
    <div class="swiper-button-prev"></div>
  </div>

  <!-- Swiper JS -->
  <script src="https://unpkg.com/swiper/swiper-bundle.min.js"></script>
  <script>
    var swiper = new Swiper('.swiper-container', {
      loop: true,
      pagination: {
        el: '.swiper-pagination',
        clickable: true,
      },
      navigation: {
        nextEl: '.swiper-button-next',
        prevEl: '.swiper-button-prev',
      },
    });
  </script>
</body>
</html>

解释说明:

  1. HTML结构

    • 使用了<div class="swiper-container">作为轮播容器。
    • 每个轮播项(图片或视频)放在<div class="swiper-slide">中。
    • 包含了分页器(pagination)和导航箭头(navigation buttons)。
  2. CSS样式

    • 设置了全屏显示,确保轮播占满整个屏幕。
    • 对图片和视频进行了样式调整,使其适应轮播项的大小。
  3. JavaScript配置

    • 使用Swiper库初始化轮播组件。
    • 配置了循环播放(loop: true),分页器(pagination)和导航按钮(navigation)。
  4. 依赖库

    • 引入了Swiper的CSS和JS文件,确保轮播功能正常工作。

上一篇:js reactive

下一篇:three.js orbitcontrols

大家都在看

js 数组打乱顺序

js 两个数组取交集

js 数组对象排序

js 对象数组排序

js 数组删掉第一个值

js fill

js fill方法

js 数组连接

js json数组

js 数组复制

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站