Coder Social home page Coder Social logo

gisyellow / ng2-lazyload-image Goto Github PK

View Code? Open in Web Editor NEW

This project forked from angularclass/ng2-lazyload-image

0.0 2.0 0.0 4.97 MB

Lazy image loader for Angular 2

Home Page: http://tjoskar.github.io/ng2-lazyload-image/

License: MIT License

JavaScript 32.84% TypeScript 65.51% HTML 1.32% CSS 0.33%

ng2-lazyload-image's Introduction

ng2-lazyload-image

Lazy image loader for Angular 2

Build Status npm version npm

Build Status

About 90 loc and no dependencies (except for angular and rxjs of course)

Demo: http://tjoskar.github.io/ng2-lazyload-image/

Requirement

The browser you targeting need to have support of WeepMap. If you need to support an older browser (like IE or Safari) you will need to include polyfill for WeekMap (see https://github.com/zloirock/core-js for example).

Installation

$ npm install ng2-lazyload-image --save

And then include it in your module (see app.module.ts):

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { LazyLoadImageModule } from 'ng2-lazyload-image';
import { AppComponent } from './app.component';

@NgModule({
    declarations: [ AppComponent ],
    imports: [ BrowserModule, LazyLoadImageModule ],
    bootstrap: [ AppComponent ]
})
export class MyAppModule {}

Usages

import { Component } from '@angular/core';

@Component({
    selector: 'image',
    template: `
        <img [src]="defaultImage" [lazyLoad]="image" [offset]="offset">
    `
})
class ImageComponent {
    defaultImage = 'https://www.placecage.com/1000/1000';
    image = 'https://images.unsplash.com/photo-1443890923422-7819ed4101c0?fm=jpg';
    offset = 100;
}

It also supports background images, by using backgroundImage:

@Component({
    selector: 'image',
    template: `
        <div [src]="defaultImage" [lazyLoad]="image" [offset]="offset"></div>
        <!--
        After it has been loaded the div will transform into:
        <div class="ng2-lazyloaded" style="background-image: url('https://images.unsplash.com/photo-1443890923422-7819ed4101c0?fm=jpg');"></div>
        -->
    `
})
class ImageComponent {
    defaultImage = 'https://www.placecage.com/1000/1000';
    image = 'https://images.unsplash.com/photo-1443890923422-7819ed4101c0?fm=jpg';
    offset = 100;
}

See example folder for more usages.

Develop

Run unit tests:

$ npm test

Run e2e tests:

$ npm run webdriver:update
$ npm run e2e

ng2-lazyload-image's People

Contributors

greenkeeperio-bot avatar csbok avatar dhardtke avatar freezing avatar greenkeeper[bot] avatar

Watchers

James Cloos avatar Dong Huang 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.