Answer the question
In order to leave comments, you need to log in
How to add slider to bootstrap modal?
The task is to create a page of images from the "brick" masonry (I use masonry) with the opening of each image separately in a modal window. I use bootstrap for the modal and slick slider for the slider.
Image block code
<div class="col-xs-12 col-sm-4 col-md-2 masonry nopadding">
<div class="mwrap" data-toggle="modal" data-target="#myModal">
<img class="img-responsive" data-value="1" src="/img/test/1.jpg">
<p class="wdesc-hide">Описание изображения</p>
</div>
</div>
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body row">
<div class="wimg-block">
<img class="wimg img-responsive" src="" />
</div>
<div class="wdesc-block ">
<p class="wdesc"></p>
<div class="wslider">
сюда генерятся блоки с img
</div>
</div>
</div>
</div>
</div>
</div>
(function($) {
var $grid = $('.masonry-container').masonry({
itemSelector: '.masonry',
percentPosition: true,
columnWidth: '.masonry'
});
$grid.imagesLoaded().progress(function() {
$grid.masonry();
});
$(document).ready(function() {
function createSlick() {
$(".wslider").not('.slick-initialized').slick({
dots: true,
slidesToShow: 3,
slidesToScroll: 1,
autoplay: true
});
}
$('.mwrap').on('click', function() {
var img = $('img', this).attr('src');
var desc = $('p', this).html();
var value = $('img', this).attr('data-value');
var arr = $('img[data-value="' + value + '"]').map(function() {
return this.src;
}).get()
var elements = $();
for (x = 0; x < arr.length; x++) {
elements = elements.add('<div><img src="' + arr[x] + '"></div>');
}
$('#myModal').on('show.bs.modal', function() {
$(".wimg").attr("src", img);
$(".wdesc").html(desc);
$('.wslider').append(elements);
createSlick();
$(window).on('resize', createSlick);
});
});
$('#myModal').on('hidden.bs.modal', function() {
})
});
})(jQuery);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question