Bootstrap snippet and html example. Bootstrap Gallery with Modal Lightbox and Carousel

This html snippet was created to help web designers, web developers, front-end and back-end developer save time. Use it for free in your project and build your app faster, You can also download the HTML, CSS, and JS code.
Tags: gallery,modal,carousel

HTML code

This is the html code used to create this bootstrap snippet, You can copy and paste the following html code inside a page with bootstrap 3.1.0 included, to get the result that you can see in the preview selection

              	  
<div class="container bootstrap snippets bootdey">
  <div class="row">
    <h1>Bootstrap 3 Lightbox using Modal</h1>
    <div class="row">
      <div class="col-lg-3 col-sm-4 col-xs-6"><a title="Image 1" href="#"><img class="thumbnail img-responsive" src="https://www.bootdey.com/image/600x350/6495ED/000000"></a></div>
      <div class="col-lg-3 col-sm-4 col-xs-6"><a title="Image 2" href="#"><img class="thumbnail img-responsive" src="https://www.bootdey.com/image/600x350/5F9EA0/000000"></a></div>
      <div class="col-lg-3 col-sm-4 col-xs-6"><a title="Image 3" href="#"><img class="thumbnail img-responsive" src="https://www.bootdey.com/image/600x350/DC143C/000000"></a></div>
      <div class="col-lg-3 col-sm-4 col-xs-6"><a title="Image 4" href="#"><img class="thumbnail img-responsive" src="https://www.bootdey.com/image/600x350/FF7F50/000000"></a></div>
      <div class="col-lg-3 col-sm-4 col-xs-6"><a title="Image 5" href="#"><img class="thumbnail img-responsive" src="https://www.bootdey.com/image/600x350/008B8B/000000"></a></div>
      <div class="col-lg-3 col-sm-4 col-xs-6"><a title="Image 6" href="#"><img class="thumbnail img-responsive" src="https://www.bootdey.com/image/600x350/00FFFF/000000"></a></div>
      <div class="col-lg-3 col-sm-4 col-xs-6"><a title="Image 8" href="#"><img class="thumbnail img-responsive" src="https://www.bootdey.com/image/600x350/FF1493/000000"></a></div>
      <div class="col-lg-3 col-sm-4 col-xs-6"><a title="Image 9" href="#"><img class="thumbnail img-responsive" src="https://www.bootdey.com/image/600x350/9400D3/000000"></a></div>
      <div class="col-lg-3 col-sm-4 col-xs-6"><a title="Image 10" href="#"><img class="thumbnail img-responsive" src="https://www.bootdey.com/image/600x350/FF69B4/000000"></a></div>
      <div class="col-lg-3 col-sm-4 col-xs-6"><a title="Image 11" href="#"><img class="thumbnail img-responsive" src="https://www.bootdey.com/image/600x350/ADD8E6/000000"></a></div>
      <div class="col-lg-3 col-sm-4 col-xs-6"><a title="Image 12" href="#"><img class="thumbnail img-responsive" src="https://www.bootdey.com/image/600x350/E6E6FA/000000"></a></div>
      <div class="col-lg-3 col-sm-4 col-xs-6"><a title="Image 13" href="#"><img class="thumbnail img-responsive" src="https://www.bootdey.com/image/600x350/B0C4DE/000000"></a></div>
    </div>
    <hr>
  </div>
</div>
<div class="modal" id="myModal" role="dialog">
  <div class="modal-dialog">
  <div class="modal-content">
    <div class="modal-header">
      <button class="close" type="button" data-dismiss="modal">×</button>
      <h3 class="modal-title"></h3>
    </div>
  	<div class="modal-body">
  		<div id="modalCarousel" class="carousel">
        <div class="carousel-inner"></div>
        <a class="carousel-control left" href="#modaCarousel" data-slide="prev"><i class="glyphicon glyphicon-chevron-left"></i></a>
        <a class="carousel-control right" href="#modalCarousel" data-slide="next"><i class="glyphicon glyphicon-chevron-right"></i></a>
      </div>
  	</div>
  	<div class="modal-footer">
  		<button class="btn btn-default" data-dismiss="modal">Close</button>
  	</div>
   </div>
  </div>
</div>  

CSS code

This is the css code used to create this bootstrap snippet, You can copy and paste the following css code inside a page with bootstrap 3.1.0 included, to get the result that you can see in the preview selection

              	  

                
body{margin-top:20px;}              
.modal-dialog {}
.thumbnail {margin-bottom:6px;}

.carousel-control.left,.carousel-control.right{
  background-image:none;
  margin-top:10%;
  width:5%;
}              

Javascript/Jquery code

This is the javascript code used to create this bootstrap snippet, You can copy and paste the following javascript code inside a page with bootstrap 3.1.0 included, to get the result that you can see in the preview selection

$(function(){
  /* copy loaded thumbnails into carousel */
  $('.row .thumbnail').on('load', function() {
    
  }).each(function(i) {
   // if(this.complete) {
        var item = $('<div class="item"></div>');
      var itemDiv = $(this).parents('div');
      var title = $(this).parent('a').attr("title");
      
      item.attr("title",title);
      $(itemDiv.html()).appendTo(item);
      item.appendTo('.carousel-inner'); 
      if (i==0){ // set first item active
       item.addClass('active');
     // }
    }
  });

  /* activate the carousel */
  $('#modalCarousel').carousel({interval:false});

  /* change modal title when slide changes */
  $('#modalCarousel').on('slid.bs.carousel', function () {
    $('.modal-title').html($(this).find('.active').attr("title"));
  })

  /* when clicking a thumbnail */
  $('.row .thumbnail').click(function(){
      var idx = $(this).parents('div').index();
      var id = parseInt(idx);
      $('#myModal').modal('show'); // show the modal
      $('#modalCarousel').carousel(id); // slide carousel to selected
      
  });
})
      

Similar snippets

Bootstrap example and template. Contact Form

Contact Form

Bootstrap example and template. Gallery with pagination

Gallery with pagination

Bootstrap example and template. collage gallery

collage gallery

Bootstrap example and template. gallery item

gallery item

Bootstrap example and template. profile edit data and skills

profile edit data and skills

Bootstrap example and template. Green chat room

Green chat room

Bootstrap example and template. Gallery of images

Gallery of images

Bootstrap example and template. notification list

notification list

Bootstrap example and template. Bootstrap Gallery with Modal Lightbox and Carousel

About this bootstrap example/template

We hope you will enjoy this awesome snippet and stay tuned for the latest updates, bootdey snippets are already used in thousands of blogs, websites and projects. We believe it will save your precious time and gives trendy look to your next web project.

We always try to offer the best beautiful and responsive source of Bootstrap code examples and components.

This code example currectly have 31.5K views, Using this bootstrap snippet you have the following benefits:

Bootstrap 3.1.0

<link rel='stylesheet' href='https://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css'>

<script src='https://netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js'></script>

This code example is based on bootstrap 3.1.0 and the grid system of this framework

Responsive

Based on bootstrap framework makes all the layouts perfectly responsive for all devices

Crossbrowser compatibility

Tested on all major browsers, it works smoothly on all of them

Jquery plugins

Great built-in plugins with jquery framework, you can easy to change all declarations

semantic html 5

Built on html / css3 the code quality is really amazing

Simple Integration

This code example can be simply integrated on existing sites and new ones too, all you need to do is copy the code and start working