Angular Bootstrap Lightbox
Angular Lightbox - Bootstrap 4 & Material Design
Note: This documentation is for an older version of Bootstrap (v.4). A
newer version is available for Bootstrap 5. We recommend migrating to the latest version of our product - Material Design for
Bootstrap 5.
Go to docs v.5
Angular Bootstrap lightbox is a group of images combined into one responsive gallery. Elements are grouped in a thumbnail grid, which can be displayed as a slideshow.
Required screenfull library
Using lightbox requires you to have installed the
Screenfull
library. Install it using the following command, and then add it to your imports in angular.json. This process is described in Quickstart Guide.
npm install --save screenfull@4.2.1
Basic example MDB Pro component
<div class="row">
<mdb-image-modal [modalImages]="imagesBasic" type="no-margin"></mdb-image-modal>
</div>
import { Component } from '@angular/core';
@Component({
selector: 'basic-lightbox',
templateUrl: './basic-lightbox.component.html',
styleUrls: ['./basic-lightbox.component.scss'],
})
export class BasicLightboxComponent {
imagesBasic = [
{ img: "https://mdbootstrap.com/img/Photos/Horizontal/Nature/12-col/img%20(117).webp", thumb: "https://mdbootstrap.com/img/Photos/Horizontal/Nature/12-col/img%20(117).webp", description: "Image 1" },
{ img: "https://mdbootstrap.com/img/Photos/Horizontal/Nature/12-col/img%20(98).webp", thumb: "https://mdbootstrap.com/img/Photos/Horizontal/Nature/12-col/img%20(98).webp", description: "Image 2" },
{ img: "https://mdbootstrap.com/img/Photos/Horizontal/Nature/12-col/img%20(131).webp", thumb: "https://mdbootstrap.com/img/Photos/Horizontal/Nature/12-col/img%20(131).webp", description: "Image 3" },
{ img: "https://mdbootstrap.com/img/Photos/Horizontal/Nature/12-col/img%20(123).webp", thumb: "https://mdbootstrap.com/img/Photos/Horizontal/Nature/12-col/img%20(123).webp", description: "Image 4" },
{ img: "https://mdbootstrap.com/img/Photos/Horizontal/Nature/12-col/img%20(118).webp", thumb: "https://mdbootstrap.com/img/Photos/Horizontal/Nature/12-col/img%20(118).webp", description: 'Image 5' },
{ img: "https://mdbootstrap.com/img/Photos/Horizontal/Nature/12-col/img%20(128).webp", thumb: "https://mdbootstrap.com/img/Photos/Horizontal/Nature/12-col/img%20(128).webp", description: 'Image 6' },
{ img: "https://mdbootstrap.com/img/Photos/Horizontal/Nature/12-col/img%20(132).webp", thumb: "https://mdbootstrap.com/img/Photos/Horizontal/Nature/12-col/img%20(132).webp", description: 'Image 7' },
{ img: "https://mdbootstrap.com/img/Photos/Horizontal/Nature/12-col/img%20(115).webp", thumb: "https://mdbootstrap.com/img/Photos/Horizontal/Nature/12-col/img%20(115).webp", description: 'Image 8' },
{ img: "https://mdbootstrap.com/img/Photos/Horizontal/Nature/12-col/img%20(133).webp", thumb: "https://mdbootstrap.com/img/Photos/Horizontal/Nature/12-col/img%20(133).webp", description: 'Image 9' }
];
}
Gallery with margins MDB Pro component
Add type="margin"
class to add a margin to your images.
<div class="row">
<mdb-image-modal [modalImages]="images" type="margin"></mdb-image-modal>
</div>
import { Component } from '@angular/core';
@Component({
selector: 'margin-lightbox',
templateUrl: './margin-lightbox.component.html',
styleUrls: ['./margin-lightbox.component.scss'],
})
export class MarginLightboxComponent {
images = [
{ img: "https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(145).webp", thumb: "https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(145).webp", description: "Image 1" },
{ img: "https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(150).webp", thumb: "https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(150).webp", description: "Image 2" },
{ img: "https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(152).webp", thumb: "https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(152).webp", description: "Image 3" },
{ img: "https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(42).webp", thumb: "https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(42).webp", description: "Image 4" },
{ img: "https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(151).webp", thumb: "https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(151).webp", description: "Image 5" },
{ img: "https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(40).webp", thumb: "https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(40).webp", description: "Image 6" },
{ img: "https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(148).webp", thumb: "https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(148).webp", description: "Image 7" },
{ img: "https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(147).webp", thumb: "https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(147).webp", description: "Image 8" },
{ img: "https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(149).webp", thumb: "https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(149).webp", description: "Image 9" }
];
}
Gallery with heading MDB Pro component
<div class="row">
<h2 class="font-weight-bold my-5 text-center mx-auto">My Projects</h2>
<mdb-image-modal [modalImages]="imagesWithHeading"></mdb-image-modal>
</div>
import { Component } from '@angular/core';
@Component({
selector: 'heading-lightbox',
templateUrl: './heading-lightbox.component.html',
styleUrls: ['./heading-lightbox.component.scss'],
})
export class HeadingLightboxComponent {
imagesWithHeading = [
{ img: "https://mdbootstrap.com/img/Mockups/Lightbox/Thumbnail/img%20(63).webp", thumb: "https://mdbootstrap.com/img/Mockups/Lightbox/Thumbnail/img%20(63).webp", description: "Image 1" },
{ img: "https://mdbootstrap.com/img/Mockups/Lightbox/Original/img%20(66).webp", thumb: "https://mdbootstrap.com/img/Mockups/Lightbox/Thumbnail/img%20(66).webp", description: "Image 2" },
{ img: "https://mdbootstrap.com/img/Mockups/Lightbox/Original/img%20(65).webp", thumb: "https://mdbootstrap.com/img/Mockups/Lightbox/Thumbnail/img%20(65).webp", description: "Image 3" },
{ img: "https://mdbootstrap.com/img/Mockups/Lightbox/Original/img%20(67).webp", thumb: "https://mdbootstrap.com/img/Mockups/Lightbox/Thumbnail/img%20(67).webp", description: "Image 4" },
{ img: "https://mdbootstrap.com/img/Mockups/Lightbox/Original/img%20(68).webp", thumb: "https://mdbootstrap.com/img/Mockups/Lightbox/Thumbnail/img%20(68).webp", description: "Image 5" },
{ img: "https://mdbootstrap.com/img/Mockups/Lightbox/Original/img%20(64).webp", thumb: "https://mdbootstrap.com/img/Mockups/Lightbox/Thumbnail/img%20(64).webp", description: "Image 6" },
{ img: "https://mdbootstrap.com/img/Mockups/Lightbox/Original/img%20(69).webp", thumb: "https://mdbootstrap.com/img/Mockups/Lightbox/Thumbnail/img%20(69).webp", description: "Image 7" },
{ img: "https://mdbootstrap.com/img/Mockups/Lightbox/Original/img%20(59).webp", thumb: "https://mdbootstrap.com/img/Mockups/Lightbox/Thumbnail/img%20(59).webp", description: "Image 8" },
{ img: "https://mdbootstrap.com/img/Mockups/Lightbox/Original/img%20(70).webp", thumb: "https://mdbootstrap.com/img/Mockups/Lightbox/Thumbnail/img%20(70).webp", description: "Image 9" }
];
}
Projects presentation MDB Pro component
<div class="row">
<h1 class="text-center text-uppercase font-weight-bold mt-5 mb-3 mt-5">My projects</h1>
<p class="text-center text-uppercase font-weight-bold">All about my work</p>
<p class="section-description mt-5 pt-2">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Fugit, error
amet numquam iure provident voluptate esse quasi, veritatis totam voluptas nostrum quisquam eum porro a
pariatur accusamus veniam. At ab ea a molestiae corrupti numquam quo beatae minima ratione magni accusantium
repellat eveniet quia vitae.</p>
<div class="row ml-3 mr-3 pb-4 pt-1">
<div class="col-md-12">
<mdb-image-modal [modalImages]="projectsImages"></mdb-image-modal>
</div>
<div class="col-md-12 text-center py-4">
<a mdbBtn color="black" outline="true" class="waves-effect"><strong>more</strong></a>
</div>
</div>
</div>
import { Component } from '@angular/core';
@Component({
selector: 'projects-lightbox',
templateUrl: './projects-lightbox.component.html',
styleUrls: ['./projects-lightbox.component.scss'],
})
export class ProjectsLightboxComponent {
projectsImages = [
{ img: "https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(135).webp", thumb: "https://mdbootstrap.com/img/Photos/Lightbox/Thumbnail/img%20(135).webp", description: "Image 1" },
{ img: "https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(128).webp", thumb: "https://mdbootstrap.com/img/Photos/Lightbox/Thumbnail/img%20(128).webp", description: "Image 2" },
{ img: "https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(133).webp", thumb: "https://mdbootstrap.com/img/Photos/Lightbox/Thumbnail/img%20(133).webp", description: "Image 3" },
{ img: "https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(131).webp", thumb: "https://mdbootstrap.com/img/Photos/Lightbox/Thumbnail/img%20(131).webp", description: "Image 4" },
{ img: "https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(130).webp", thumb: "https://mdbootstrap.com/img/Photos/Lightbox/Thumbnail/img%20(130).webp", description: "Image 5" },
{ img: "https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(132).webp", thumb: "https://mdbootstrap.com/img/Photos/Lightbox/Thumbnail/img%20(132).webp", description: "Image 6" },
{ img: "https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(134).webp", thumb: "https://mdbootstrap.com/img/Photos/Lightbox/Thumbnail/img%20(134).webp", description: "Image 7" },
{ img: "https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(1).webp", thumb: "https://mdbootstrap.com/img/Photos/Lightbox/Thumbnail/img%20(1).webp", description: "Image 8" },
{ img: "https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(131).webp", thumb: "https://mdbootstrap.com/img/Photos/Lightbox/Thumbnail/img%20(131).webp", description: "Image 9" }
];
}
Angular Lightbox - API
In this section you will find informations about required modules and available inputs, outputs, methods and events of lightbox component.
Modules used
In order to speed up your application, you can choose to import only the modules you actually need, instead of importing the entire MDB Angular library. Remember that importing the entire library, and immediately afterwards a specific module, is bad practice, and can cause application errors.
import { LightBoxModule, WavesModule } from 'ng-uikit-pro-standard'
Components
ImageModalComponent
Selector: mdb-image-modal
Type: ImageModalComponent
Inputs
Name | Type | Default | Description | Example |
---|---|---|---|---|
modalImages
|
[{img: string, thumb: string, description: string, caption: string}] | - | Input for filling lightbox with images. | [modalImages]="images" |
type
|
string | - | Input changing type of the lightbox. Possible values are margin, no-margin. | type="no-margin" |
Methods
Below methods are available in ImageModalComponent
Name | Description |
---|---|
prevImage()
|
Navigates to the previous image in the lightbox view. |
nextImage()
|
Navigates to the next image in the lightbox view. |