抄
创建于 2024-03-21 16:54:12
<!DOCTYPE html>
<html lang=“en”>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Swiper 幻灯片示例</title>
<!-- 引入 Swiper 的 CSS -->
<link rel="stylesheet" href="https://unpkg.com/swiper@8/swiper-bundle.min.css">
</head>
<body>
<!– Swiper 容器 –>
<div class=“swiper”>
<div class="swiper-wrapper">
<div class="swiper-slide">幻灯片 1</div>
<div class="swiper-slide">幻灯片 2</div>
<div class="swiper-slide">幻灯片 3</div>
<!-- 更多幻灯片... -->
</div>
<!-- 如果需要分页器 -->
<div class="swiper-pagination"></div>
<!-- 如果需要导航按钮 -->
<div class="swiper-button-next"></div>
<div class="swiper-button-prev"></div>
<div class="swiper-scrollbar"></div>
</div>
<!– 引入 Swiper 的 JavaScript –>
<script src=”https://unpkg.com/swiper@8/swiper-bundle.min.js”></script>
<script>
// 当 DOM 加载完成后初始化 Swiper
document.addEventListener('DOMContentLoaded', function () {
var mySwiper = new Swiper('.swiper', {
// Swiper 配置
slidesPerView: 1, // 同时可见的幻灯片数量
spaceBetween: 30, // 幻灯片之间的间距
loop: true, // 是否循环播放
pagination: {
el: '.swiper-pagination',
clickable: true, // 分页器是否可点击
},
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
scrollbar: {
el: '.swiper-scrollbar',
hide: true, // 是否隐藏滚动条
},
// 可以添加更多配置选项,如自动播放等
});
});
</script>
</body>
</html>