Plugin for lazy loading images in Angular

Downloads in past


178161.2.06 years ago6 years agoMinified + gzip package size for angular-lazy-img in KB


Lightweight lazy load images plugin. Only 1kb after gziping. Pure JavaScript, only Angular as dependency.


  1. bower install --save angular-lazy-img
  2. Include angular-lazy-img in your HTML.
<script src="<your-bower-components>/angular-lazy-img/release/angular-lazy-img.js"></script>
  1. Inject the angular-lazy-img module in your application.
angular.module('your.module', [


Just add lazy-img attribute with source to file that you want to lazy load
```html ```
If you want show spinner put it in src attribute
```html ```
You want to lazy load background image? No problem, add directive to anything you like and it will handle the rest.
If you need to run the image check manually (for example when clicking on tabs that filter your image result), you can trigger it that way:
```js $rootScope.$emit('lazyImg:refresh'); ```
On success and error lazyImg will trigger events on $rootScope - lazyImg:success and lazyImg:error, passing as first param image


Inside your config require 'lazyImgConfigProvider' and set custom options.
```js angular.module('your.module',
).config('lazyImgConfigProvider', function(lazyImgConfigProvider){
var scrollable = document.querySelector('#scrollable');
  offset: 100, // how early you want to load image (default = 100)
  errorClass: 'error', // in case of loading image failure what class should be added (default = null)
  successClass: 'success', // in case of loading image success what class should be added (default = null)
  onError: function(image){}, // function fired on loading error
  onSuccess: function(image){}, // function fired on loading success
  container: angular.element(scrollable) // if scrollable container is not $window then provide it here
) ```

Use a scrollable container in a dynamic page

Just add ``lazyImgContainer`` attribute to your scrollable container to be considered when you scroll him.


Copyright 2014, Paweł Wszoła (