-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
61 lines (48 loc) · 1.1 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
<!DOCTYPE html>
<html>
<head>
<title>壁纸</title>
<meta charset="utf-8">
<style type="text/css">
*{
margin: 0;
padding: 0;
}
img{
display: block;
width: 100vw;
height: 100vh;
}
</style>
</head>
<body>
<script type="text/javascript">
let suipian = document.createDocumentFragment();
for(var i = 1; i < 201; i++){
var img = document.createElement('img');
img.setAttribute('data-src', `./image/Wallpaper (${i}).jpg`);
suipian.append(img);
}
document.body.append(suipian);
window.addEventListener('scroll', function (e){
let imgHeight = document.getElementsByTagName('img')[0].offsetHeight;
let tmp = window.pageYOffset / imgHeight;
abc(parseInt(tmp) + 1);
});
window.addEventListener('load', function(){
let img = document.getElementsByTagName('img')[0];
img.src = img.getAttribute('data-src');
});
function abc(index){
let img = document.getElementsByTagName('img')[index];
if(!img) return;
if(img.getAttribute('data-src')){
img.src = img.getAttribute('data-src');
img.removeAttribute('data-src');
}else{
return;
}
}
</script>
</body>
</html>