"Gallery with pagination"
Bootstrap 3.0.3 Snippet by hossam

<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <!------ Include the above in your HEAD tag ----------> <div class="gallery"> <div class="container"> <div class="row overflow"> <div class="col-xs-3 gallery-item"> <a href="#galleryImg1" data-toggle="modal" data-target="#myModal" > <img src="http://placehold.it/1366x768&text=Fourth image" id="s>" STYLE="WIDTH:260px; HEIGHT:132px" class="img-responsive img-gallery" alt="First image" onclick="getinfo(this.id)"> </a> </div> <!-- /.col --> </div> <!--/.row --> </div> <!-- /.container --> </div> <!-- /.gallery --> <form method="POST" action="Prescription.jsp?type=<%=type%>"> <button class="button2">back</button> </form> <div id="myModal" class="modal fade" role="dialog"> <div class="modal-dialog"> <!-- Modal content--> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h4 class="modal-title"><b>Date : </b></h4> <h4 style="display:inline;"> <div id="date" style="display:inline;"></div> </h4 > </div> <div class="modal-body"> <h5 style="display:inline;"><b>Description : </b></h5><div id="d" style="display:inline;"></div> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> </div> </div> </div> </div>
.gallery{ margin-top: 100px; } .gallery-item{ margin-bottom: 30px; } .modal-footer{ text-align: center; } .pagination{ margin: 0; }
$(document).ready(function(){ $('.link-gallery').click(function(){ var galleryId = $(this).attr('data-target'); var currentLinkIndex = $(this).index('a[data-target="'+ galleryId +'"]'); createGallery(galleryId, currentLinkIndex); createPagination(galleryId, currentLinkIndex); $(galleryId).on('hidden.bs.modal', function (){ destroyGallry(galleryId); destroyPagination(galleryId); }); $(galleryId +' .carousel').on('slid.bs.carousel', function (){ var currentSlide = $(galleryId +' .carousel .item.active'); var currentSlideIndex = currentSlide.index(galleryId +' .carousel .item'); setTitle(galleryId, currentSlideIndex); setPagination(++currentSlideIndex, true); }) }); function createGallery(galleryId, currentSlideIndex){ var galleryBox = $(galleryId + ' .carousel-inner'); $('a[data-target="'+ galleryId +'"]').each(function(){ var img = $(this).html(); var galleryItem = $('<div class="item">'+ img +'</div>'); galleryItem.appendTo(galleryBox); }); galleryBox.children('.item').eq(currentSlideIndex).addClass('active'); setTitle(galleryId, currentSlideIndex); } function destroyGallry(galleryId){ $(galleryId + ' .carousel-inner').html(""); } function createPagination(galleryId, currentSlideIndex){ var pagination = $(galleryId + ' .pagination'); var carouselId = $(galleryId).find('.carousel').attr('id'); var prevLink = $('<li><a href="#'+ carouselId +'" data-slide="prev">«</a></li>'); var nextLink = $('<li><a href="#'+ carouselId +'" data-slide="next">»</a></li>'); prevLink.appendTo(pagination); nextLink.appendTo(pagination); $('a[data-target="'+ galleryId +'"]').each(function(){ var linkIndex = $(this).index('a[data-target="'+ galleryId +'"]'); var paginationLink = $('<li><a data-target="#carouselGallery" data-slide-to="'+ linkIndex +'">'+ (linkIndex+1) +'</a></li>'); paginationLink.insertBefore('.pagination li:last-child'); }); setPagination(++currentSlideIndex); } function setPagination(currentSlideIndex, reset = false){ if (reset){ $('.pagination li').removeClass('active'); } $('.pagination li').eq(currentSlideIndex).addClass('active'); } function destroyPagination(galleryId){ $(galleryId + ' .pagination').html(""); } function setTitle(galleryId, currentSlideIndex){ var imgAlt = $(galleryId + ' .item').eq(currentSlideIndex).find('img').attr('alt'); $('.modal-title').text(imgAlt); } });

Related: See More


Questions / Comments: