93 lines
2.6 KiB
HTML
93 lines
2.6 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Swiper 5.2.1 3D 轮播图</title>
|
|
<!-- 引入 Swiper CSS -->
|
|
<link rel="stylesheet" href="https://unpkg.com/swiper@5.2.1/css/swiper.min.css">
|
|
<style>
|
|
/* 基础样式 */
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
margin: 0;
|
|
padding: 0;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
height: 100vh;
|
|
background-color: #f0f0f0;
|
|
}
|
|
|
|
.swiper-container {
|
|
width: 300px;
|
|
height: 200px;
|
|
}
|
|
|
|
.swiper-slide {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
background-color: #3498db;
|
|
color: white;
|
|
font-size: 2rem;
|
|
border: 2px solid #2980b9;
|
|
box-sizing: border-box;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<!-- Swiper 容器 -->
|
|
<div class="swiper-container">
|
|
<div class="swiper-wrapper">
|
|
<div class="swiper-slide">1</div>
|
|
<div class="swiper-slide">2</div>
|
|
<div class="swiper-slide">3</div>
|
|
<div class="swiper-slide">4</div>
|
|
<div class="swiper-slide">5</div>
|
|
</div>
|
|
<!-- 分页器 -->
|
|
<div class="swiper-pagination"></div>
|
|
<!-- 导航按钮 -->
|
|
<div class="swiper-button-next"></div>
|
|
<div class="swiper-button-prev"></div>
|
|
</div>
|
|
|
|
<!-- 引入 Swiper JS -->
|
|
<script src="https://unpkg.com/swiper@5.2.1/js/swiper.min.js"></script>
|
|
<script>
|
|
// 初始化 Swiper
|
|
const swiper = new Swiper('.swiper-container', {
|
|
// 启用 3D 效果
|
|
effect: 'coverflow',
|
|
grabCursor: true, // 鼠标悬停时显示抓手光标
|
|
centeredSlides: true, // 居中显示
|
|
slidesPerView: 'auto', // 自适应显示幻灯片数量
|
|
coverflowEffect: {
|
|
rotate: 50, // 旋转角度
|
|
stretch: 0, // 拉伸距离
|
|
depth: 100, // 深度
|
|
modifier: 1, // 效果强度
|
|
slideShadows: true, // 启用幻灯片阴影
|
|
},
|
|
// 分页器
|
|
pagination: {
|
|
el: '.swiper-pagination',
|
|
clickable: true,
|
|
},
|
|
// 导航按钮
|
|
navigation: {
|
|
nextEl: '.swiper-button-next',
|
|
prevEl: '.swiper-button-prev',
|
|
},
|
|
// 自动播放
|
|
autoplay: {
|
|
delay: 3000, // 3 秒切换一次
|
|
disableOnInteraction: false, // 用户操作后不停止自动播放
|
|
},
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
</html> |