Bootstrap Lightbox Multiple Images – Modal Gallery

Bootstrap Lightbox Multiple Images - Modal Gallery
Code Snippet:bootstrap modallery
Author: Luiz Gonçalves
Published: January 17, 2024
Last Updated: January 22, 2024
Downloads: 8,963
License: MIT
Edit Code online: View on CodePen
Read More

A lightweight jQuery plugin to create a bootstrap lightbox with multiple images. The plugin magically creates an image gallery in the Bootstrap modal. These images can be navigated through the next, previous buttons or with keyboard arrow keys. Also, it generates inline thumbnails in the modal gallery.

How to Create Multiple Images Bootstrap Lightbox

1. Load the jQuery and Bootstrap framework into the HTML document to get started with Modal Gallery plugin.

<!-- jQuery -->
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>

<!-- Bootstrap CSS -->
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

<!-- Bootstrap JS -->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

2. After that, include the modal gallery‘s CSS and JavaScript files in your website.

<!-- Modal Gallery CSS -->
<link rel="stylesheet" href="src/css/bootstrap.modallery.min.css">

<!-- Modal Gallery Js -->
<script src='src/js/bootstrap.modallery.min.js'></script>

3. Create a markup structure for the gallery as follows after including all assets.

 <div class="container">
    <div class="row">
      <div class="col-md-3">
        <img src="img/sm-1.jpg" data-to="img/lg-1.jpg" data-caption="This one has a caption" class="modallery">
      </div>
      <div class="col-md-3">
        <img src="img/sm-2.jpg" data-to="img/lg-2.jpg" data-caption="Here is a caption" class="modallery">
      </div>
      <div class="col-md-3">
        <img src="img/sm-3.jpg" data-to="img/lg-3.jpg" data-caption="This one also has a caption" class="modallery">
      </div>
      <div class="col-md-3">
        <img src="img/sm-4.jpg" data-to="img/lg-4.jpg" class="modallery">
      </div>
      <div class="col-md-3">
        <img src="img/sm-5.jpg" data-to="img/lg-5.jpg" data-caption="This one has a caption" class="modallery">
      </div>
      <div class="col-md-3">
        <img src="img/sm-6.jpg" data-to="img/lg-6.jpg" class="modallery">
      </div>
      <div class="col-md-3">
        <img src="img/sm-7.jpg" data-to="img/lg-7.jpg" data-caption="This one also has a caption" class="modallery">
      </div>
      <div class="col-md-3">
        <img src="img/sm-8.jpg" data-to="img/lg-8.jpg" class="modallery">
      </div>
    </div>

4. Finally, initialize the plugin globally with a document selector.

$(document).ready(function(){

$(this).modallery();

});

Advanced Configuration Options

The following are some advanced configuration options to create/customize a “modal gallery”.

title This option defines the title and shows it on the top of the modal box. Default: ‘Image Gallery’, Type: String.

$(document).modallery({
   title: "My Modal Gallery",
});
navigate Decide whether to show navigation (next & previous) buttons to navigate images. Default: false, Type: Boolean.

$(document).modallery({
   navigate: true,
});
arrows Show or hide arrow icons. Default: false, Type: Boolean.

$(document).modallery({
   arrows: true,
});
keypress Allow navigating images through keyboard arrow keys. Default: false, Type: Boolean.

$(document).modallery({
   keypress: true,
});
size Sets the Bootstrap available sizes for modals: sm or lg etc. Default: null, Type: String.

$(document).modallery({
   size: "lg",
});
caller The selector, images class for Modallery to find. Default: ‘modallery’, Type: String.

$(document).modallery({
   caller: "my-class",
});

That’s all! hopefully, you have successfully created a lightbox with multiple images using Boostrap. If you have any questions or facing any issues, feel free to comment below.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About CodeHim

Free Web Design Code & Scripts - CodeHim is one of the BEST developer websites that provide web designers and developers with a simple way to preview and download a variety of free code & scripts. All codes published on CodeHim are open source, distributed under OSD-compliant license which grants all the rights to use, study, change and share the software in modified and unmodified form. Before publishing, we test and review each code snippet to avoid errors, but we cannot warrant the full correctness of all content. All trademarks, trade names, logos, and icons are the property of their respective owners... find out more...

Please Rel0ad/PressF5 this page if you can't click the download/preview link

X