Giter VIP home page Giter VIP logo

angular-lazy-img's Introduction

angular-lazy-img

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

Installation

  1. bower install --save angular-lazy-img

  2. Include angular-lazy-img in your HTML.

    <script src="<your-bower-components>/angular-lazy-img/angular-lazy-img.js"></script>
  3. Inject the angular-lazy-img module in your application.

    angular.module('your.module', [
        'angularLazyImg'
    ]);

Usage

Just add lazy-img attribute with source to file that you want to lazy load

<img lazy-img='photo.jpeg' />

If you want show spinner put it in src attribute

<img src='spinner.gif' lazy-img='photo.jpeg' />

You want to lazy load background image? No problem, add directive to anything you like and it will handle the rest.

<div lazy-img='photo.jpeg'></div>

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:

$rootScope.$emit('lazyImg.runCheck');

Configuration

Inside your config require 'lazyImgConfigProvider' and set custom options.

angular.module('your.module', [
  'angularLazyImg'
]).config(['lazyImgConfigProvider', function(lazyImgConfigProvider){
  scrollable = document.querySelector('#scrollable')
  lazyImgConfigProvider.setOptions({
    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
  });
}])

Author

Copyright 2014, Paweł Wszoła ([email protected])

angular-lazy-img's People

Contributors

jlubean avatar pentiado avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.