本代码会根据2020-06-01与当前时间相差天数选取对应的图片
图片文件目录如下


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
<!DOCTYPE html>
<html>

<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>title</title>
<style>
#web_bg {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
min-width: 1500px;
z-index: -10;
zoom: 1;
background-color: #fff;
background-repeat: no-repeat;
background-size: cover;
-webkit-background-size: cover;
-o-background-size: cover;
background-position: center 0;
}
</style>
</head>

<body>
<!--背景图片-->
<div id="web_bg"></div>
<!--其他代码 ... -->
</body>
<script>
// 提前加载缓存,防止闪屏
for (let index = 1; index < 60; index++) {
let img = new Image();
img.src = "imgs/" + index + ".png";
img.onload = function () {
document.getElementById("web_bg").style = "background-image: url(" + img.src + ")"

}
}

function changeImg() {
var i = 0;
var end = new Date('2020-06-01');
console.log(end)
var start = new Date()
interval = (end - start) / (24 * 3600 * 1000)
console.log(parseInt(interval))
var i = parseInt(interval) + 1
let img = new Image();
img.src = "imgs/" + i + ".png";
img.onload = function () {
document.getElementById("web_bg").style = "background-image: url(" + img.src + ")"
}
}


// 一分钟刷新一次
setInterval("changeImg()", 1000 * 60);
</script>

</html>