carousel-js
Version:
Easily implement a dynamic carousel using minimal javascript. Supports Meteor, AngularJS, React, Polymer and any CSS library, e.g. Bootstrap.
76 lines (67 loc) • 2.15 kB
HTML
<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>