Codepen: http://codepen.io/srkimir/pen/mGbrf
Github: https://github.com/srkimir/thumbnails-carousel
While you slide left or right appropriately, thumbnails gets selected and change their opacity to be different among others thumbnails. You can also click on thumbnails to show the appropriate image on carousel.
HTML
Add child <ul>
of thumbnails in the end of carousel bootstrap parent, like:
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<!-- Bootstrap carousel code -->
...
<!-- Thumbnails -->
<ul class="thumbnails-carousel clearfix">
<li><img src="images/1_tn.jpg" alt="1_tn.jpg"></li>
<li><img src="images/2_tn.jpg" alt="1_tn.jpg"></li>
<li><img src="images/3_tn.jpg" alt="1_tn.jpg"></li>
<li><img src="images/4_tn.jpg" alt="1_tn.jpg"></li>
</ul>
</div>
CSS
ul.thumbnails-carousel {
padding: 5px 0 0 0;
margin: 0;
list-style-type: none;
text-align: center;
}
ul.thumbnails-carousel .center {
display: inline-block;
}
ul.thumbnails-carousel li {
margin-right: 5px;
float: left;
cursor: pointer;
}
.controls-background-reset {
background: none !important;
}
.active-thumbnail {
opacity: 0.4;
}
.indicators-fix {
bottom: 70px;
}
JavaScript:
// thumbnails.carousel.js jQuery plugin
;(function(window, $, undefined) {
var conf = {
center: true,
backgroundControl: false
};
var cache = {
$carouselContainer: $('.thumbnails-carousel').parent(),
$thumbnailsLi: $('.thumbnails-carousel li'),
$controls: $('.thumbnails-carousel').parent().find('.carousel-control')
};
function init() {
cache.$carouselContainer.find('ol.carousel-indicators').addClass('indicators-fix');
cache.$thumbnailsLi.first().addClass('active-thumbnail');
if(!conf.backgroundControl) {
cache.$carouselContainer.find('.carousel-control').addClass('controls-background-reset');
}
else {
cache.$controls.height(cache.$carouselContainer.find('.carousel-inner').height());
}
if(conf.center) {
cache.$thumbnailsLi.wrapAll("<div class='center clearfix'></div>");
}
}
function refreshOpacities(domEl) {
cache.$thumbnailsLi.removeClass('active-thumbnail');
cache.$thumbnailsLi.eq($(domEl).index()).addClass('active-thumbnail');
}
function bindUiActions() {
cache.$carouselContainer.on('slide.bs.carousel', function(e) {
refreshOpacities(e.relatedTarget);
});
cache.$thumbnailsLi.click(function(){
cache.$carouselContainer.carousel($(this).index());
});
}
$.fn.thumbnailsCarousel = function(options) {
conf = $.extend(conf, options);
init();
bindUiActions();
return this;
}
})(window, jQuery);
// Kick it
$('.thumbnails-carousel').thumbnailsCarousel({});
Additionally, you can pass center (default: true) and backgroundControl
(default: false) if you want (or no) to center your thumbnails or backgroundControl
if you want (or no) controls background which is activated on hover in bootstrap carousel.