jQuery Lightbox Gallery with Thumbnails – mBox

jQuery Lightbox Gallery with Thumbnails - mBox
Code Snippet:mBox
Author: Marek Bartula
Published: January 11, 2024
Last Updated: January 22, 2024
Downloads: 8,154
License: MIT
Edit Code online: View on CodePen
Read More

The mBox is a lightweight and really easy-to-use jQuery lightbox gallery with thumbnails. It gets all images from a specific container and shows them in a popup lightbox gallery. Users can easily navigate next and previous images with iconic buttons or with thumbnail navigation. The plugin used Font Awesome icons for the gallery interface.

Moreover, you can easily enable/disable plugin features with its Boolean options. You can also customize it with additional CSS.

How to Create jQuery Lightbox Gallery

1. Load the jQuery and Font Awesome (for icons) and Bootstrap CSS into your website/app project.

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

<!-- Font Awesome 5 -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">

<!-- Bootstrap CSS -->
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">

Note: The use of Bootstrap CSS is optional (for basic image layout).

2. Now, also include mBox‘s CSS and JavaScript files into your HTML document.

<!-- mBox CSS -->
<link rel="stylesheet" href="css/mBox.css">

<!-- mBox JS -->
<script src = "js/mBox.js"></script>

3. Create a div element with a unique id and place some images in it after loading all plugin assets.

<div id="myGallery" class="lightbox-gallery">
   <img src="img/flowers.jpg" title="gallery image 1">
   <img src="img/flowers.jpg" title="gallery image 2">
   <img src="img/flowers.jpg" title="gallery image 3">
   <img src="img/flowers.jpg" title="gallery image 4">
</div>

4. Some CSS styles for your inline images on the page.

.lightbox-gallery img{
   width: 100px;
   height: auto;
   display: inline-block;
   margin: 5px;
}

5. Initialize the mBox plugin in the jQuery document ready function to activate the lightbox gallery.

$(document).ready(function(){

   $("#myGallery").mBox();

});

Advanced Configuration Options for jQuery Lightbox

The following are some advanced configuration options to create/customize “jQuery lightbox gallery thumbnails”.

Option Description, Default, Type
imagesPerPage It defines a number of thumbnails to display on a single page. Default: 3, Type: Number.

$("#myGallery").mBox({
   imagesPerPage: 4,
});
displayTitle Decide whether to display the title of the image. The plugin gets the title from the “title” attribute of an image. Default: true, Type: Boolean.

$("#myGallery").mBox({
   displayTitle: false,
});
displayThumbnails Show/hide thumbnail navigation in a lightbox. Default: true, Type: Boolean.

$("#myGallery").mBox({
   displayThumbnails: true,
});
keyboardNavigation Enable/disable keyboard arrow keys navigation for images. Default: true, Type: Boolean.

$("#myGallery").mBox({
   keyboardNavigation: true,   
});

That’s all! hopefully, you have successfully created a lightbox gallery. If you have any questions or facing 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...