It supports a variety of content types, including images, galleries, HTML5/YouTube/Vimeo videos, iframe content, AJAX content, inline content, and much more.
1. Install and import the DimBox.js library.
# NPM $ npm i dimbox
// ES Module import dimbox from 'dimbox';
// Browser <link rel="stylesheet" href="dist/css/dimbox.min.css" /> <script src="dist/js/dimbox.min.js"></script>
2. Create modal popups using the following HTML data attributes:
<!-- Image Lightbox --> <a href="1.jpg" data-dimbox="my-image" data-dimbox-caption="Image Description"> Image </a> <!-- Video Lightbox --> <a href="https://www.youtube.com/embed/j4a2uCvbfAc" data-dimbox="youtube" data-dimbox-ratio="16x9"> YouTube Video </a> <a href="https://player.vimeo.com/video/43588364" data-dimbox="vimeo" data-dimbox-ratio="16x9"> Vimeo Video </a> <a href="/path/to/1.mp4" data-dimbox="html5video"> HTML5 Video </a> <!-- AJAX Modal --> <a href="/path/to/endpoint/" data-dimbox="ajax" data-dimbox-type="ajax"> Ajax Content </a> <!-- Iframe Modal --> <a href="/path/to/url/" data-dimbox="iframe"> iFrame Content </a> <!-- Inline Modal --> <a href="#inlineContent" data-dimbox="inline"> Inline Content </a> <div id="inlineContent" class="d-none"> Make sure to hide the DIV on page load </div>
3. Override the default configs.
dimbox.setConfig({
// close the modal on click outside
closeOnOverlayClick: true,
// Fullscreen options
fullscreen: false,
showFullscreenButton: true,
svgFullscreenButton: '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M1.5 1a.5.5 0 0 0-.5.5v4a.5.5 0 0 1-1 0v-4A1.5 1.5 0 0 1 1.5 0h4a.5.5 0 0 1 0 1zM10 .5a.5.5 0 0 1 .5-.5h4A1.5 1.5 0 0 1 16 1.5v4a.5.5 0 0 1-1 0v-4a.5.5 0 0 0-.5-.5h-4a.5.5 0 0 1-.5-.5M.5 10a.5.5 0 0 1 .5.5v4a.5.5 0 0 0 .5.5h4a.5.5 0 0 1 0 1h-4A1.5 1.5 0 0 1 0 14.5v-4a.5.5 0 0 1 .5-.5m15 0a.5.5 0 0 1 .5.5v4a1.5 1.5 0 0 1-1.5 1.5h-4a.5.5 0 0 1 0-1h4a.5.5 0 0 0 .5-.5v-4a.5.5 0 0 1 .5-.5"/></svg>',
svgFullscreenExitButton: <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M5.5 0a.5.5 0 0 1 .5.5v4A1.5 1.5 0 0 1 4.5 6h-4a.5.5 0 0 1 0-1h4a.5.5 0 0 0 .5-.5v-4a.5.5 0 0 1 .5-.5m5 0a.5.5 0 0 1 .5.5v4a.5.5 0 0 0 .5.5h4a.5.5 0 0 1 0 1h-4A1.5 1.5 0 0 1 10 4.5v-4a.5.5 0 0 1 .5-.5M0 10.5a.5.5 0 0 1 .5-.5h4A1.5 1.5 0 0 1 6 11.5v4a.5.5 0 0 1-1 0v-4a.5.5 0 0 0-.5-.5h-4a.5.5 0 0 1-.5-.5m10 1a1.5 1.5 0 0 1 1.5-1.5h4a.5.5 0 0 1 0 1h-4a.5.5 0 0 0-.5.5v4a.5.5 0 0 1-1 0z"/></svg>
// the image icon used in thumbnails for image type content if no thumbnail image could be loaded
svgImageIcon: <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-image" viewBox="0 0 16 16"><path d="M6.002 5.5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0"/><path d="M2.002 1a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V3a2 2 0 0 0-2-2zm12 1a1 1 0 0 1 1 1v6.5l-3.777-1.947a.5.5 0 0 0-.577.093l-3.71 3.71-2.66-1.772a.5.5 0 0 0-.63.062L1.002 12V3a1 1 0 0 1 1-1z"/></svg>,
// 16x9, 4x3, 1x1 and 9x16
iframeRatio: '16x9',
// default selector
selector: 'a[data-dimbox]',
// allows the user to download the media
showDownloadButton: true,
// custom icons
svgCloseButton: '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M2.146 2.854a.5.5 0 1 1 .708-.708L8 7.293l5.146-5.147a.5.5 0 0 1 .708.708L8.707 8l5.147 5.146a.5.5 0 0 1-.708.708L8 8.707l-5.146 5.147a.5.5 0 0 1-.708-.708L7.293 8 2.146 2.854Z"/></svg>',
svgDownloadButton: '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5z"/><path d="M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708l3 3z"/></svg>',
svgPrevNextButton: '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708z"/></svg>',
svgVideoIcon: '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-play-fill" viewBox="0 0 16 16"><path d="m11.596 8.697-6.363 3.692c-.54.313-1.233-.066-1.233-.697V4.308c0-.63.692-1.01 1.233-.696l6.363 3.692a.802.802 0 0 1 0 1.393"/></svg>',
// or light
theme: 'dark',
// When set to true gallery thumbnail images are shown below the image when DimBox is open.
// This requires the gallery to have more than one item.
// By default the image used as link will be shown as a thumbnail.
// If the link element doesn't contain an image a generic placeholder will be used.
thumbnails: false,
// video options
videoAutoplay: true,
videoControls: true,
videoLoop: false,
videoVolume: null,
// XHR response type
xhrResponseType: 'json',
// custom templates
ajaxTemplate: `
<div class="dimbox-ajax-container">
<div class="dimbox-ajax-content">{{content}}</div>
<div class="dimbox-caption">{{caption}}</div>
</div>
`,
imageTemplate: `
<figure class="dimbox-figure">
<img src="{{src}}" class="dimbox-image" alt="{{alt}}" />
<figcaption class="dimbox-caption">{{caption}}</figcaption>
</figure>`,
iframeTemplate: `
<div class="dimbox-iframe-container">
<iframe src="{{src}}" class="dimbox-iframe"></iframe>
<div class="dimbox-caption">{{caption}}</div>
</div>
`,
inlineTemplate: `
<div class="dimbox-inline-container">
<div class="dimbox-inline-content">{{content}}</div>
<div class="dimbox-caption">{{caption}}</div>
</div>
`,
sequenceTemplate: '<span class="dimbox-sequence-current">{{current}}</span> / <span class="dimbox-sequence-total">{{total}}</span>',
videoTemplate: `
<div class="dimbox-video-container">
<video src="{{src}}" class="dimbox-video"></video>
<div class="dimbox-caption">{{caption}}</div>
</div>
`,
// callbacks
onBeforeOpen: function() {
console.log('onBeforeOpen event callback here hi!');
},
onAfterOpen: function() {
console.log('onAfterOpen event callback here hi!');
},
onBeforeUpdateContent: function() {
console.log('onBeforeUpdateContent event callback here hi!');
},
onAfterUpdateContent: function() {
console.log('onAfterUpdateContent event callback here hi!');
},
onContentLoaded: function() {
console.log('onContentLoaded event callback here hi!');
},
onDownload: function() {
console.log('onDownload event callback here hi!');
},
onBeforeEnterFullscreen: function() {
console.log('onBeforeEnterFullscreen event callback here hi!');
},
onAfterEnterFullscreen: function() {
console.log('onAfterEnterFullscreen event callback here hi!');
},
onBeforeExitFullscreen: function() {
console.log('onBeforeExitFullscreen event callback here hi!');
},
onAfterExitFullscreen: function() {
console.log('onAfterExitFullscreen event callback here hi!');
},
onBeforeClose: function() {
console.log('onBeforeClose event callback here hi!');
},
onAfterClose: function() {
console.log('onAfterClose event callback here hi!');
}
});
4. API methods.
// close
dimbox.close();
// go to the next item
dimbox.next();
// back to the previous item
dimbox.previous();
// open an element
var myAElement = document.getElementById('myAElement');
dimbox.open(myAElement); v1.2.1 (06/05/2025)
v1.2.0 (02/22/2025)
v1.1.4 (12/14/2024)
v1.1.3 (11/16/2024)
v1.1.2 (09/11/2024)
v1.1.1 (09/11/2024)
v1.1.0 (07/06/2024)
v1.0.6 (07/01/2024)
v1.0.5 (06/30/2024)
v1.0.4 (06/23/2024)
v1.0.3 (09/11/2023)
The post All-in-One Modal Lightbox Solution For Web Developers – DimBox.js appeared first on CSS Script.
Women’s reproductive rights – and abortion access – won big Monday in Pennsylvania’s Commonwealth Court.…
FREEPORT, Ill. (WTVO) — Recent heavy rainfall is only making issues worse in the city…
BROWN COUNTY, Ind. (WOWO) — Indiana Governor Mike Braun and the Department of Natural Resources…
Full spoilers follow for Daredevil: Born Again Season 2, Episode 6, "Requiem," which is streaming…
Don't pay full price for your AirPods from the Apple Store. For a limited time,…
INDIANAPOLIS, Ind. (WOWO) — Indiana Governor Mike Braun announced on Monday that he has signed…
This website uses cookies.