All Projects → jesusbotella → Ngx Lazy Load Images

jesusbotella / Ngx Lazy Load Images

Licence: mit
Image lazy load library for Angular 2+

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Ngx Lazy Load Images

Aspnetcore Angular Universal
ASP.NET Core & Angular Universal advanced starter - PWA w/ server-side rendering for SEO, Bootstrap, i18n internationalization, TypeScript, unit testing, WebAPI REST setup, SignalR, Swagger docs, and more! By @TrilonIO
Stars: ✭ 1,455 (+1789.61%)
Mutual labels:  ssr, angular2, angular4
Angulartics2
Vendor-agnostic analytics for Angular2 applications.
Stars: ✭ 963 (+1150.65%)
Mutual labels:  angular2, angular4
Ngvas
An Angular2/Angular4 library for HTML Canvas.
Stars: ✭ 31 (-59.74%)
Mutual labels:  angular2, angular4
Angular2
Angular 2 Seed
Stars: ✭ 75 (-2.6%)
Mutual labels:  angular2, angular4
Angular Redux Ngrx Examples
Sample projects with Angular (4.x) + Angular CLI + ngrx (Redux) + Firebase
Stars: ✭ 73 (-5.19%)
Mutual labels:  angular2, angular4
Bootstrap
Open Source JS plugins
Stars: ✭ 13 (-83.12%)
Mutual labels:  angular2, angular4
Angular2 Social Login
Simple client side social authentication for Angular2 application.
Stars: ✭ 34 (-55.84%)
Mutual labels:  angular2, angular4
Ng Sticky
Angular 4 sticky, have header or any component sticky easy to use.
Stars: ✭ 25 (-67.53%)
Mutual labels:  angular2, angular4
Angular Tree Component
A simple yet powerful tree component for Angular (>=2)
Stars: ✭ 1,031 (+1238.96%)
Mutual labels:  angular2, angular4
Awesome Angular
📄 A curated list of awesome Angular resources
Stars: ✭ 8,160 (+10497.4%)
Mutual labels:  angular2, angular4
Drip Ionic3
「水滴打卡」App Open Source Code Base On Ionic V3 Framework
Stars: ✭ 74 (-3.9%)
Mutual labels:  angular2, angular4
Ng2 Dnd
Angular 2 Drag-and-Drop without dependencies
Stars: ✭ 861 (+1018.18%)
Mutual labels:  angular2, angular4
Lozad.js
🔥 Highly performant, light ~1kb and configurable lazy loader in pure JS with no dependencies for responsive images, iframes and more
Stars: ✭ 6,932 (+8902.6%)
Mutual labels:  images, lazy-loading
Nebular
💥 Customizable Angular UI Library based on Eva Design System 🌚✨Dark Mode
Stars: ✭ 7,368 (+9468.83%)
Mutual labels:  angular2, angular4
Angular2 Carousel
An lightweight , touchable and responsive library to create a carousel for angular 2 / 4 / 5
Stars: ✭ 26 (-66.23%)
Mutual labels:  angular2, angular4
Jquery.lazy
A lightweight, fast, feature-rich, powerful and highly configurable delayed content, image and background lazy loading plugin for jQuery & Zepto.
Stars: ✭ 965 (+1153.25%)
Mutual labels:  images, lazy-loading
Egeo
EGEO is the open-source UI library used to build Stratio's UI. It includes UI Components, Utilities, Services and much more to build user interfaces quickly and with ease. The library is distributed in AoT mode.
Stars: ✭ 69 (-10.39%)
Mutual labels:  angular2, angular4
Angular Prest
pREST component for Angular
Stars: ✭ 16 (-79.22%)
Mutual labels:  angular2, angular4
Angular Select2
select2 in angular(>=2.0-release).
Stars: ✭ 16 (-79.22%)
Mutual labels:  angular2, angular4
Angular Contacts Demo
Angular demo(SSR) base on Angular CLI
Stars: ✭ 42 (-45.45%)
Mutual labels:  ssr, angular4

ngx-lazy-load-images

FOSSA Status

ngx-lazy-load-images is a image lazy load library for Angular 2+.

The library allows to lazy load images from your web application using the MutationObserver and the IntersectionObserver. Images will be loaded as soon as they enter the viewport in a non-blocking way.

It supports <img> tags as well as background images.

Installation

You can install the library via npm with this command:

npm install ngx-lazy-load-images --save

Usage

1. Import the LazyLoadImagesModule

Import LazyLoadImagesModule from the ngx-lazy-load-images package, and add it to the NgModule imports array of your component.

import { NgModule } from '@angular/core';
import { LazyLoadImagesModule } from 'ngx-lazy-load-images';

@NgModule({
  imports: [
    LazyLoadImagesModule
  ]
})
export class AppComponent {}

2. Use the lazy-load-images directive

Add the lazy-load-images directive to the tag containing all the DOM image nodes to lazy load:

<!-- Image tags -->
<div class="image-list" lazy-load-images>
  <img *ngFor="let imageUrl in images" [attr.data-src]="imageUrl">
</div>

<!-- Background images -->
<div class="image-list" lazy-load-images>
  <div *ngFor="let imageUrl in images" [attr.data-background-src]="imageUrl"></div>
</div>

The container can have any HTML or components inside along with the images. But the less nodes inside the directive, the faster it will be.

Intersection Observer Configuration

If you want to make some configuration changes to the Intersection Observer, you can do it by passing an object to the lazy-load-images directive. The object takes the Intersection Observer configuration parameters as keys.

<div class="image-list" [lazy-load-images]="{ rootMargin: '50px' }"></div>

3. Set the data-src or data-background-src attribute

Set the data-src or data-background-src attribute in the images or tags that you want to lazy load.

The data-src attribute allows to lazy load images inside <img> tags. You can define it by passing a variable to the attribute, interpolating a variable, or inserting the URL directly:

<img [attr.data-src]="imageUrlVariable">
<img attr.data-src="{{ imageUrlVariable }}">
<img data-src="https://example.com/cute_kitten.jpg">

The data-background-src attribute lazy loads background images inside any HTML tag. It works the same way as the data-src attribute:

<div [attr.data-background-src]="imageUrlVariable"></div>
<div attr.data-background-src="{{ imageUrlVariable }}"></div>
<div data-background-src="https://example.com/cute_kitten.jpg"></div>

4. Have fun 🎉

Performance

Browser Compatibility

This library has been tested and known to work in the latest version of all major browsers.

The WICG Intersection Observer Polyfill is bundled within the module to use the Intersection Observer API in the non-compatible browsers. Avoid importing it in your application too, as it may cause unexpected issues.

However, the compatibility with older browsers is limited by the Mutation Observer support, which is known to work in:

Chrome
26+
Firefox
14+
Safari
6+
Edge
Internet Explorer
11+
Opera
15+
Android
4.4+

License

MIT

FOSSA Status

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].