-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.html
117 lines (115 loc) · 2.32 KB
/
demo.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>simple-lazyload</title>
</head>
<script src="./lazyload.js"></script>
<style>
@keyframes slide-up {
0% {
transform: translateY(0);
opacity: 0;
}
1% {
transform: translateY(40px);
opacity: 0;
}
100% {
transform: translateY(0);
opacity: 1;
}
}
.top {
height: 200vh;
}
.box1, .box2, .box3 {
width: 300px;
height: 400px;
background-color: #ededed
}
.box2, .box3 {
background-position: center;
background-size: cover;
background-repeat: no-repeat;
}
img {
width: 100%;
height: 100%;
}
.middle {
height: 100vh;
}
.bottom {
position: relative;
padding: 10vh 20vw;
width: 50vw;
height: 100vh;
border: 3px solid #ED7B60;
border-radius: 10px;
}
.bottom::before {
content: '';
display: block;
position: absolute;
left: 0;
right: 0;
top: 200px;
width: 100%;
height: 10px;
background-color: #ededed;
}
.inner {
opacity: 0;
}
.slide-up {
opacity: 0;
transform: translateY(40px);
animation-name: slide-up;
animation-duration: 1.7s;
animation-delay: .6s;
animation-fill-mode: forwards;
animation-timing-function: cubic-bezier(.25, .46, .45, .94);
}
</style>
<body>
<div class="top">
<div>img</div>
<div class="box1">
<img src="" data-img="./images/1.jpg" alt="">
</div>
</div>
<div class="middle">
<div>background-image</div>
<div class="box2" data-img="./images/2.jpg"></div>
</div>
<div class="bottom">
<div class="inner" data-class="slide-up">
<div>class & background-image</div>
<div class="box3" data-img-custom="./images/3.jpg"></div>
<div>新添加了slide-up类, 我会有slide-up的效果</div>
</div>
</div>
</body>
<script>
const lazy = new Lazyload()
// 支持img 和 class 两种模式
lazy.set({
mode: 'img',
dataset: 'data-img',
offset: '50%',
delay: 1000,
}).set({
mode: 'class',
dataset: 'data-class',
offset: '-80%',
}).set({
mode: 'img',
dataset: 'data-img-custom',
offset: '-80%',
delay: 0,
})
</script>
</html>