-
Notifications
You must be signed in to change notification settings - Fork 12
/
carousel-image-lazy-loading.html
75 lines (67 loc) · 2.1 KB
/
carousel-image-lazy-loading.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
<html>
<head>
<style>
.carousel-panel {
width: 400px;
height: 200px;
opacity: 0;
visibility: hidden;
position: absolute;
}
.carousel-panel img {
display: block;
width: 100%;
height: auto;
}
.carousel-panel-active {
opacity: 1;
visibility: visible;
transition: opacity .2s ease-out;
}
.carousel-thumb {
width: 20px;
height: 20px;
background-color: darkblue;
display: inline-block;
cursor: pointer;
}
.image-loading {
/* add image loader indicator styles here */
}
</style>
</head>
<body>
<p>Click on one of the thumbnails below and notice how the images only load when <br />
you click on a thumbnail image. The first photo loads immediately fyi.</p>
<div class="carousel-thumbs">
<div class="carousel-thumb"></div>
<div class="carousel-thumb"></div>
<div class="carousel-thumb"></div>
</div>
<div class="carousel">
<div class="carousel-panel">
<img data-lazy-src="http://www.gstatic.com/webp/gallery/1.jpg" src="" />
</div>
<div class="carousel-panel">
<img data-lazy-src="http://www.gstatic.com/webp/gallery/2.jpg" src="" />
</div>
<div class="carousel-panel">
<img data-lazy-src="http://www.gstatic.com/webp/gallery/3.jpg" src="" />
</div>
</div>
<script src="../dist/carousel.js"></script>
<script>
var carousel = new Carousel({
panels: document.getElementsByClassName('carousel-panel'),
panelActiveClass: 'carousel-panel-active',
lazyLoadAttr: 'data-lazy-src',
assetLoadingClass: 'image-loading',
thumbnails: document.getElementsByClassName('carousel-thumb')
});
// goes to first panel and lazy loads the image inside of it
carousel.goTo(0);
// FYI: it will also add the "image-loading" css class to the image element while its loading
// so you can add a loading style, loading indicator, etc
</script>
</body>
</html>