forked from mdn/sw-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lazy_devrel_demo.html
62 lines (52 loc) · 1.95 KB
/
lazy_devrel_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
<!DOCTYPE html>
<head>
<title>loading=lazy demo</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
</head>
<body>
<style>
img {
display: block;
margin: 1em 0;
}
.fail img {
display: none;
}
pre {
border: 2px solid red;
}
.fail pre {
border-color: red;
background: pink;
}
.pass pre {
border-color: darkgreen;
background: lightgreen;
}
</style>
<br><br><br>
<div style="height:10000px;"></div>
<br><br><br>
<img loading='lazy' data-src='img/images.jpeg' width='400' height='400' alt='' class='lazyload' onload='console.log("onload img1")'>
<img loading='lazy' data-src='img/w3schools_green.jpg' width='401' height='401' alt='' class='lazyload' onload='console.log("onload img2")'>
<img loading='lazy' data-src='https://placekitten.com/400/400' width='400' height='400' alt='' class='lazyload'>
<img loading='lazy' data-src='https://placekitten.com/401/401' width='401' height='401' alt='' class='lazyload'>
<img loading='lazy' data-src='http://placekitten.com/402/402' width='402' height='402' alt='' class='lazyload'>
<img loading='lazy' data-src='http://placekitten.com/403/403' width='403' height='403' alt='' class='lazyload'>
<script>
if ('loading' in HTMLImageElement.prototype) {
const images = document.querySelectorAll("img.lazyload");
images.forEach(img => {
img.src = img.dataset.src;
});
} else {
// Dynamically import the LazySizes library
let script = document.createElement("script");
script.async = true;
script.src =
"https://cdnjs.cloudflare.com/ajax/libs/lazysizes/4.1.8/lazysizes.min.js";
document.body.appendChild(script);
}
</script>
</body>
</html>