1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <style>
- body{
- margin: 0;
- }
- #carousel-container {
- width: 100%;
- height: 400px;
- position: relative;
- overflow: hidden;
- }
- #carousel-container img {
- width: 100%;
- height: auto;
- position: absolute;
- top: 0;
- left: 0;
- opacity: 0;
- transition: opacity 0.5s ease-in-out;
- }
- </style>
- </head>
- <body>
- <div id="carousel-container">
- <img src="./themes/laughing/source/img/1.png" alt="Image 1">
- <img src="./themes/laughing/source/img/2.png" alt="Image 1">
- <img src="./themes/laughing/source/img/3.png" alt="Image 1">
- </div>
- <script>
- // 获取轮播图容器和图片元素
- var container = document.getElementById('carousel-container');
- var images = container.getElementsByTagName('img');
- // 定义索引变量
- var currentIndex = 0;
- // 切换图片的函数
- function showImage(index) {
- // 隐藏所有图片
- for (var i = 0; i < images.length; i++) {
- images[i].style.opacity = 0;
- }
- // 显示指定索引的图片
- images[index].style.opacity = 1;
- }
- // 自动切换图片的函数
- function autoSlide() {
- // 切换到下一张图片
- currentIndex++;
- if (currentIndex >= images.length) {
- currentIndex = 0;
- }
- // 显示当前图片
- showImage(currentIndex);
- }
- // 定时触发自动切换
- setInterval(autoSlide, 2000);
- </script>
- </body>
- </html>
|