Lightbox
Angular Bootstrap 5 Lightbox component
Responsive lightbox built with Bootstrap 5, Angular and Material Design. Lightbox is a responsive gallery with the option to enlarge selected photos.
MDB lightbox is a group of images combined in one responsive gallery. Elements are grouped in a thumbnail grid, which can be displayed as a slideshow.
Note: Read the API tab to find all available options and advanced customization
Basic example
A basic example of a lightbox with the most common use case with the bootstrap grid.
Image optimization
To ensure the proper performance of the page, it is recommended to include thumbnails of
images in the src attribute. Then in the
img
input add the path to the image with higher resolution. If the
img
input is omitted, the lightbox will display the same image as in
the reduced size.
Shadows and rounded corners
You can improve the look of the images by adding shadows and rounded corners.
Different sizes
Loaded images can have any aspect ratio. Their size will be automatically adjusted to the window when you open the lightbox.
Zoom level
The zoomLevel
input allows you to define the size of a single zoom
in / zoom out.
Disabled image
By adding a lightbox-disabled
class to any image, you can exclude it from your
lightbox. In the example below, the third image has been disabled.
Captions
Image captions can be added using the caption
input. If it is not
set, the data is taken from the alt
attribute. When you want to disable caption,
leave the caption
empty.
Outside access
The lightbox can be successfully operated via TypeScript. There are many public methods
available such as open
, slide
, zoomIn
,
zoomOut
, or close
. All are described in the API tab.
Lightbox - API
Import
Inputs
Name | Type | Default | Description |
---|---|---|---|
zoomLevel
|
number | 1 |
Defines zoom level while zooming in or out. |
fontAwesome
|
string | 'free' |
Defines version of Font Awesome library. Available options are 'free' and 'pro'. |
img |
string |
|
Defines regular image to load when gallery is open. If not set, the value of
src attribute is taken.
|
caption
|
string |
|
Defines caption of the image. If not set, the value of
alt attribute is taken.
|
Outputs
Name | Type | Description |
---|---|---|
lightboxOpen
|
EventEmitter<void> | Emitted when a lightbox has been toggled. |
lightboxOpened
|
EventEmitter<void> | Emitted when a lightbox is opened. |
lightboxSlide
|
EventEmitter<void> | Emitted when a lightbox has been slided. |
lightboxSlided
|
EventEmitter<void> | Emitted after an image slide. |
lightboxZoomIn
|
EventEmitter<void> | Emitted when an image has been zoom in. |
lightboxZoomedIn
|
EventEmitter<void> | Emitted after an image is zoomed in. |
lightboxZoomOut
|
EventEmitter<void> | Emitted when an image has been zoom out. |
lightboxZoomedOut
|
EventEmitter<void> | Emitted after an image is zoomed out. |
lightboxClose
|
EventEmitter<void> | Emitted when a lightbox has been toggled. |
lightboxClosed
|
EventEmitter<void> | Emitted when a lightbox is closed. |
Methods
Name | Description | Example |
---|---|---|
open(lightboxItem: MdbLightboxItemDirective) |
Opens the gallery and activates image set by the target key. Default is the first image. | lightbox.open(lightboxItem) |
slide(direction) |
Slides an image in the gallery. Available options: left ,
right , first , last . Dafault is right direction.
|
lightbox.slide('last') |
zoomIn |
Zooms in active image by one level. | lightbox.zoomIn() |
zoomOut
|
Zooms out active image by one level. | lightbox.zoomOut() |
toggleFullscreen
|
Toggles fullscreen. | lightbox.toggleFullscreen() |
reset |
Resets changed parameters such as position, zoom or fullscreen. | lightbox.reset() |
close |
Closes the gallery. | lightbox.close() |
CSS variables
As part of MDB’s evolving CSS variables approach, lightbox now uses local CSS variables on
mdb-lightbox-modal
for enhanced real-time customization. Values for the CSS variables are
set via Sass, so Sass customization is still supported, too.