Lazy loading
Angular Bootstrap 5 Lazy loading
Bootstrap 5 Lazy Loading is a feature, that allows you to load images or videos only when they are visible on the screen.
Note: Read the API tab to find all available options and advanced customization
Basic example
Lazy Loading will automatically initialize after adding mdbLazyLoad
directive to
your img
or video
element. It is important to add
[attr.data-src]
attribute - otherwise, directive will throw an error. You can use
[container]
input to bind directive to specific parent container. In this case,
the directive will listen to the container scroll event.
Scroll down to see an image
Offset
Use [offset]
input to define an additional amount of pixels after which image or
video will show.
Scroll more down to load a picture.
Error
Use [errorPlaceholder]
input to define a picture that will show if image or video
doesn't load.
Animations
Use code below to specify which animation you want to activate when element loads.
Lazy loading - API
Import
Inputs
Name | Type | Default | Description |
---|---|---|---|
container
|
HTMLElement | - |
Defines parent container of the element |
delay
|
number | 0 |
Defines delay after which element will show |
errorPlaceholder
|
string | - |
Defines a picture that is shown if an error with showing element occurs |
offset
|
number | 0 |
Defines an additional offset after which element will show |
loadingPlaceholder
|
string | - |
Defines a picture that is shown before loading a proper element |
Outputs
Name | Type | Description |
---|---|---|
loadingEnd
|
EventEmitter<void> | Event fired when element is fully loaded |
loadingError
|
EventEmitter<void> | Event fired if error occurs while loading |
loadingStart
|
EventEmitter<void> | Event fired when loading starts |