Pure JavaScript Image Lightbox – Zbox.js

Category: Modal & Popup | July 13, 2018
Author: lenonmauer
Official Page: Go to Website
Last Update:August 1, 2023

The Zbox.js is a simple and lightweight solution for pure Javascript image lightbox. It can be used on image or link to show a bigger version of the image.

It is a flexible image viewer of the javascript library which is responsive and mobile friendly. When a user clicks on the image thumbnail, it shows a bigger image with fade animation.

How to Use Image Lightbox with Javascript

Simply add the zbox.js before head closing.

<script type="text/javascript" src="zbox.js"></script>

Add an image or your own link on your webpage.

<div class="imgDiv">
    Image 1:<br><br><img height="100" src="img/img1.jpg"/>
<div class="imgDiv">
    Image 2:<br><br><a href="img/img2.jpg"/>Image Link</a>

Call the main lightbox function and do change the options as you want.

var a;
document.addEventListener("DOMContentLoaded", function(event) {
	a = new Zbox({
		overlayClick 	: true, /* overlay click close the modal. */
		fadeTime 		: 1000, /* Time in ms for fade effect. */
		loading  		: "Loading image message",
		querySelector 	: "img, a", /* Elements to apply zbox. */