|
发表于 2023-4-26 20:47:52
|
显示全部楼层
要实现5张图片每10秒循环播放,您可以使用JavaScript和HTML来实现。请参考以下代码:
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>图片循环播放</title>
- <style>
- .image-container {
- width: 200px;
- height: 200px;
- border-radius: 4px;
- position: relative;
- }
- .image-container img {
- position: absolute;
- top: 0;
- left: 0;
- border-radius: 4px;
- display: none;
- }
- .image-container img.active {
- display: block;
- }
- </style>
- </head>
- <body>
- <div class="image-container">
- <img src="https://example.com/image1.jpg" alt="Image 1" class="active" />
- <img src="https://example.com/image2.jpg" alt="Image 2" />
- <img src="https://example.com/image3.jpg" alt="Image 3" />
- <img src="https://example.com/image4.jpg" alt="Image 4" />
- <img src="https://example.com/image5.jpg" alt="Image 5" />
- </div>
- <script>
- (function() {
- let images = document.querySelectorAll('.image-container img');
- let currentIndex = 0;
- function changeImage() {
- images[currentIndex].classList.remove('active');
- currentIndex = (currentIndex + 1) % images.length;
- images[currentIndex].classList.add('active');
- }
- setInterval(changeImage, 10000);
- })();
- </script>
- </body>
- </html>
复制代码
这段代码创建了一个包含5张图片的图片循环播放器。图片会每隔10秒(10000毫秒)切换一次。将图片的URL替换为您要使用的实际图片URL即可。 |
|