-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
69 lines (62 loc) · 2.44 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>如初的随机背景API展示</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f0f0f0;
overflow: hidden; /* 防止滚动条出现 */
background-size: cover; /* 填满整个背景 */
}
#randomImage {
display: none; /* 隐藏 img 标签 */
}
#imageSource {
position: absolute;
bottom: 20px;
color: #333;
font-size: 18px;
text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.8);
}
</style>
<script>
function getRandomImage() {
try {
// 定义三个文件夹及其对应的图片数量
const folders = [
{ name: "img1", count: 850 },
{ name: "img2", count: 457 },
{ name: "pc", count: 448 }
];
// 随机选择一个文件夹
const selectedFolder = folders[Math.floor(Math.random() * folders.length)];
// 在选择的文件夹中随机选择一张图片
const randomImageIndex = Math.floor(Math.random() * selectedFolder.count) + 1;
const randomImage = `https://img-cdn.99j.us.kg/${selectedFolder.name}/ruchu-${randomImageIndex}.jpg`; // 加入域名
// 设置body的背景图
document.body.style.backgroundImage = `url('${randomImage}')`;
// 显示图片地址
document.getElementById('imageSource').innerText = randomImage;
} catch (error) {
console.error("获取随机图片时出现错误:", error);
alert("无法加载随机图片,请稍后再试。");
}
}
// 页面加载时随机显示一张图片
window.onload = getRandomImage;
</script>
</head>
<body>
<div id="imageSource">这里将显示随机图片的地址</div>
<img id="randomImage" src="" alt="随机图片">
<script charset="UTF-8" id="LA_COLLECT" src="//sdk.51.la/js-sdk-pro.min.js"></script>
<script>LA.init({id:"3JyDN38xyGD2ZeaJ",ck:"3JyDN38xyGD2ZeaJ"})</script>
</body>
</html>