I am trying to create a simple lightbox using Bootstrap carousel and Modal. Please take a look at sample file which I have here .
What I would like to do is starting the Modal Carousel as same slide (current slide) of the main carousel. As you can see from the example when I start the Modal it just start from the first item but I need to start from current active slide.
Can you please let me know how to do this?
<div class="container">
<div class="well span9 columns">
<div id="myCarousel" class="carousel slide">
<div class="carousel-inner">
<div class="item active">
<a href=".bell" data-toggle="modal"><img src="http://bootstrapdocs.com/v2.0.3/docs/assets/img/bootstrap-mdo-sfmoma-01.jpg" alt=""/></a>
</div>
<div class="item">
<img src="http://bootstrapdocs.com/v2.0.3/docs/assets/img/bootstrap-mdo-sfmoma-02.jpg" alt=""/>
</div>
<div class="item">
<img src="http://bootstrapdocs.com/v2.0.3/docs/assets/img/bootstrap-mdo-sfmoma-03.jpg" alt=""/>
</div>
</div>
<a class="left carousel-control" href="#myCarousel" data-slide="prev">‹</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">›</a>
</div>
<!-- Modal -->
<div id="bell" class="modal hide fade bell" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Modal header</h3>
</div>
<div class="modal-body">
<div id="myCarousel2" class="carousel slide">
<div class="carousel-inner">
<div class="item active">
<img src="http://bootstrapdocs.com/v2.0.3/docs/assets/img/bootstrap-mdo-sfmoma-01.jpg" alt=""/>
</div>
<div class="item">
<img src="http://bootstrapdocs.com/v2.0.3/docs/assets/img/bootstrap-mdo-sfmoma-02.jpg" alt=""/>
</div>
<div class="item">
<img src="http://bootstrapdocs.com/v2.0.3/docs/assets/img/bootstrap-mdo-sfmoma-03.jpg" alt=""/>
</div>
</div>
<a class="left carousel-control" href="#myCarousel2" data-slide="prev">‹</a>
<a class="right carousel-control" href="#myCarousel2" data-slide="next">›</a>
</div>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
</div>
</div>
<div class="btn-group" data-toggle="buttons-radio">
<button type="button" class="btn btn-inverse"><a href=".bell" data-toggle="modal"><i class="icon-resize-full icon-white"></i></a>
</button>
</div>
</div>
Thansk
This seems to work.
$('.bell').on('show', function() {
var targetSlide = parseInt($('#myCarousel .active').index('#myCarousel .item'));
$('#myCarousel2').carousel(targetSlide);
});
This gets the current index showing on the main carousel.
$('#myCarousel .active').index('#myCarousel .item')
This sets the current slide of the modal carousel.
$('#myCarousel2').carousel(/*Number here*/);
Here is a jsFillde with the above code.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.