-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.html
123 lines (108 loc) · 3.88 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
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
118
119
120
121
122
123
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,minimum-scale=1.0,initial-scale=1,maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>hunt | lazy loading image example</title>
<meta name="description" content="Minimal library to observe nodes entering and leaving the viewport. Example lazy loading images.">
<!-- site styles -->
<style>
body {
color: #010120;
font-family: -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto, Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji', 'Segoe UI Symbol';
line-height: 1.65;
font-size: 17px;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.container {
max-width: 40rem;
margin: 0 auto;
padding: 0 1rem;
}
.excerpt {
color: #505060;
}
a {
color: #4242ef;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
code {
font-family: Menlo,Consolas,Monaco,monospace;
}
pre {
background-color: rgba(0,0,10,0.025);
border-radius: 4px;
font-size: 14px;
line-height: 1.5;
overflow: auto;
padding: .75rem 1rem;
}
pre .c {
opacity: 0.5;
}
.lazy {
background-image: linear-gradient(to right, #9090b8, #bdbdd6);
display: inline-block;
margin: 2rem 0;
height: 300px;
width: 300px;
}
.lazy:nth-child(2n) {
transform: translate(-10%, 10%)
}
</style>
</head>
<body>
<header>
<div class="container">
<h1>hunt</h1>
<p class="excerpt">Minimal library to observe nodes entering and leaving the viewport. Library written by <a href="//jeremenichelli.io">Jeremias Menichelli</a> and contributors.</p>
<p>Example of code lazy loading images when they become visible.</p>
</div>
</header>
<main>
<div class="container">
<pre><code>import <strong>Hunt</strong> from <strong>'huntjs'</strong>;
<span class="c">// lazy loading images using dataset and hunt</span>
const <strong>lazyImages</strong> = document.querySelectorAll('img.lazy');
let observer = new <strong>Hunt</strong>(lazyImages, {
<strong>enter</strong>: (image) => image.src = image.dataset.src
});</code></pre>
<div class="lazy--images">
<img data-src="https://source.unsplash.com/300x300/?water" alt="" class="lazy">
<img data-src="https://source.unsplash.com/300x300/?mountain" alt="" class="lazy">
<img data-src="https://source.unsplash.com/300x300/?fire" alt="" class="lazy">
<img data-src="https://source.unsplash.com/300x300/?plants" alt="" class="lazy">
<img data-src="https://source.unsplash.com/300x300/?plane" alt="" class="lazy">
<img data-src="https://source.unsplash.com/300x300/?cars" alt="" class="lazy">
<img data-src="https://source.unsplash.com/300x300/?bicycle" alt="" class="lazy">
<img data-src="https://source.unsplash.com/300x300/?moon" alt="" class="lazy">
<img data-src="https://source.unsplash.com/300x300/?dessert" alt="" class="lazy">
<img data-src="https://source.unsplash.com/300x320/?tokyo" alt="" class="lazy">
</div>
</div>
</main>
<footer>
<div class="container">
<p><em>All photos randomly picked up from <a href="//unsplash.com">Unsplash</a></em></p>
<p><a href="//github.com/jeremenichelli/hunt">Check the code and full API on GitHub</a></p>
</div>
</footer>
<script src="https://unpkg.com/huntjs/dist/hunt.umd.js"></script>
<script>
window.addEventListener('DOMContentLoaded', function() {
var imageObserver = new Hunt(document.getElementsByClassName('lazy'), {
enter: function(el) {
el.src = el.dataset.src;
}
});
})
</script>
</body>
</html>