0.1.0 • Published 5 years ago
cm-ngx-video-lazyloader v0.1.0
cm-ngx-video-lazyloader
cm-ngx-video-lazyloader is an Angular library for lazy loading videos using IntersectionObserver.
Install
npm install --save cm-ngx-video-lazyloaderUsage
- Import
CmNgxVideoLazyloaderModuleinto your root module. - Add
lazyLoadVideodirective to the video tag. - Place the video url inside
data-srcattribute instead ofsrcattribute. The url will be dynamically assinged to thesrcattribute when the video is in viewport.
Example:
<video lazyLoadVideo class="card-video" loop autoplay muted id="1" poster="https://example.org/assets/Americas-poster.jpg">
<source data-src="https://example.org/assets/Americas.mp4" type="video/mp4" />
Browser not supported
</video>If you wish to lazy load the poster as well, then you can pass in an optional input param [lazyLoadPoster]="true" in the video tag and place the poster url inside the data-poster attribute. This attribute is set as false by default.
Example:
<video lazyLoadVideo [lazyLoadPoster]="true" data-poster="https://example.org/...></video>
Test Development server
Run ng serve for a dev server. Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files.