liufumingren e8605149c0 初始化
2026-08-06 17:04:35 +08:00

103 lines
3.3 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>图片轮播</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
background-color: #f5f5f5;
}
.image-container {
width: 80%;
max-width: 600px;
height: 400px;
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
border: 2px solid #333;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
background-color: white;
}
.image-container img {
max-width: 100%;
max-height: 100%;
cursor: pointer;
transition: opacity 0.3s ease;
}
.counter {
margin-top: 20px;
font-size: 18px;
color: #666;
}
h1 {
color: #333;
margin-bottom: 30px;
}
</style>
</head>
<body>
<h1>图片轮播展示</h1>
<div class="image-container">
<img id="current-image" src="" alt="轮播图片">
</div>
<div class="counter">
图片 <span id="current-index">1</span> / <span id="total-count">0</span><span id="current-weight"></span>
</div>
<script>
// 图片链接数组
const imageUrls = {$list};
let currentIndex = 0;
const imageElement = document.getElementById('current-image');
const currentIndexElement = document.getElementById('current-index');
const currentIndexElement2 = document.getElementById('current-weight');
const totalCountElement = document.getElementById('total-count');
// 初始化显示第一张图片
function init() {
if (imageUrls.length > 0) {
imageElement.src = "https://ye4s.wms.gztbyc.com/barcode/build?text="+imageUrls[currentIndex][0];
totalCountElement.textContent = imageUrls.length;
currentIndexElement2.textContent = imageUrls[currentIndex][1];
currentIndexElement.textContent = currentIndex + 1;
} else {
imageElement.alt = "没有可用的图片";
}
}
// 点击切换到下一张图片
imageElement.addEventListener('click', function() {
if (imageUrls.length === 0) return;
currentIndex = (currentIndex + 1) % imageUrls.length;
imageElement.src = "https://ye4s.wms.gztbyc.com/barcode/build?text="+imageUrls[currentIndex][0];
currentIndexElement2.textContent = imageUrls[currentIndex][1];
currentIndexElement.textContent = currentIndex + 1;
// 添加淡入淡出效果
imageElement.style.opacity = 0;
setTimeout(() => {
imageElement.style.opacity = 1;
}, 300);
});
// 页面加载时初始化
window.addEventListener('load', init);
</script>
</body>
</html>