swiper异形的slide自动轮播
时间: 2024-04-01 15:28:06 浏览: 168
Vue封装Swiper实现图片轮播效果
以下是使用Swiper插件实现异形slide自动轮播的示例代码:
```html
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://unpkg.com/swiper/swiper-bundle.min.css" />
<style>
.swiper-container {
width: 400px;
height: 300px;
}
.swiper-slide {
background-size: cover;
background-position: center;
}
</style>
</head>
<body>
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide" style="background-image: url('imgs/1.jpg');"></div>
<div class="swiper-slide" style="background-image: url('imgs/2.jpg');"></div>
<div class="swiper-slide" style="background-image: url('imgs/3.jpg');"></div>
<div class="swiper-slide" style="background-image: url('imgs/4.jpg');"></div>
<div class="swiper-slide" style="background-image: url('imgs/5.jpg');"></div>
</div>
</div>
<script src="https://unpkg.com/swiper/swiper-bundle.min.js"></script>
<script>
var swiper = new Swiper('.swiper-container', {
autoplay: true,
slidesPerView: 'auto',
centeredSlides: true,
spaceBetween: 30,
loop: true,
});
</script>
</body>
</html>
```
这段代码首先引入了Swiper插件的CSS和JS文件。然后,创建了一个具有指定宽度和高度的swiper容器,并在其中添加了多个swiper-slide元素,每个元素都包含一个背景图片。最后,通过JavaScript代码初始化Swiper实例,并设置了自动播放、异形slide、循环等选项。
阅读全文