html5轮播图代码
时间: 2024-11-07 17:03:07 浏览: 4
HTML5全屏图片左右滑动轮播特效代码
5星 · 资源好评率100%
HTML5轮播图通常通过JavaScript库如Swiper、Slick、Owl Carousel等来创建。下面是一个简单的基于Swiper库的HTML5轮播图的基本代码示例:
```html
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>HTML5轮播图</title>
<link rel="stylesheet" href="https://unpkg.com/swiper@6/swiper.min.css">
</head>
<body>
<div class="swiper-container">
<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>
<!-- Add Pagination -->
<div class="swiper-pagination"></div>
</div>
<script src="https://unpkg.com/swiper@6/swiper.min.js"></script>
<script>
new Swiper('.swiper-container', {
pagination: {
el: '.swiper-pagination',
clickable: true,
},
loop: true, // 设置循环模式
autoplay: { delay: 3000 } // 自动切换,延迟3秒
});
</script>
</body>
</html>
```
这个例子中,`.swiper-container`是轮播图的容器,`.swiper-slide`是每张图片,`.swiper-pagination`用于显示页码。Swiper的配置项设置自动播放、循环滑动等功能。
阅读全文