κΈ°μ‘΄ Ionic 2 νλ‘μ νΈ(Angular 2.0.0-rc.4λ₯Ό μ¬μ©νλ 2.0.0-beta.11)λ₯Ό μ€ννκ³ μμ΅λλ€. μ€μΉ λ° μ€μ νμ§λ§ λ€μ μ€λ₯κ° κ³μ λ°μν©λλ€(λ°νμμ μ€λ₯κ° λ°μν©λλ€. μ»΄νμΌ μ λ¬Έμ μμ).
μ€ν Npm:
$ npm install ng2-lazyload-image --save
λ΄ κ΅¬μ± μμλ‘ κ°μ Έμ€κΈ°:
import { LazyLoadImageDirective } from 'ng2-lazyload-image';
μ§μμ΄ μ€μ :
directives: [ LazyLoadImageDirective ]
λ³μ λ° κΈ°λ³Έκ° μ€μ :
export class PostComponent {
defaultImage: any = 'build/assets/preloader.gif';
offset = 100;
@Input() feedImage: string = 'build/assets/blank-default-feed-bg.png';
}
λ΄ ν
νλ¦Ώμμ:
<img [src]="defaultImage" [lazyload]="feedImage" [offset]="offset" class="feed-image">
λ΄κ° κ°κ³Όνκ³ μλ κ²μ΄ μμμ§λ λͺ¨λ₯΄μ§λ§ κ·Έκ²μ΄ 무μμΈμ§ λ³Ό μ μλ κ² κ°μ΅λλ€.
μλ ,
λ¬Έμ λ₯Ό μ¬νν μ μμ΅λλ€. μ΄λ€ λ²μ μ ng2-lazyload-imageλ₯Ό μ¬μ©νκ³ μμ΅λκΉ? λ΄κ° λ³Ό μ μλλ‘ νλ‘μ νΈκ° μ€ν μμ€μ λκΉ?
$ npm install -g ionic<strong i="8">@beta</strong>
$ ionic --version
2.0.0-beta.37
$ ionic start ionic-lazy-load-images --v2
$ cd ionic-lazy-load-images
$ npm install [email protected] --save
$ ionic serve
`app/pages/home/home.html:
<ion-header>
<ion-navbar>
<ion-title>Home</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding class="home" #container>
<h2>Welcome to Ionic!</h2>
<p>
This starter project comes with simple tabs-based layout for apps
that are going to primarily use a Tabbed UI.
</p>
<p style="height: 1000px;">
Take a look at the <code>app/</code> directory to add or change tabs,
update any existing page or create new pages.
</p>
<img
style="height: 1099px;"
[src]="defaultImage"
[lazyLoad]="image"
[offset]="offset"
[scrollTarget]="container._scroll._el">
</ion-content>
`app/pages/home/home.ts:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { LazyLoadImageDirective } from 'ng2-lazyload-image';
@Component({
templateUrl: 'build/pages/home/home.html',
directives: [ LazyLoadImageDirective ]
})
export class HomePage {
defaultImage = 'https://www.placecage.com/1000/1000';
image = 'https://hd.unsplash.com/photo-1441765425173-8fd330fb4a02';
offset = 100;
constructor(private navCtrl: NavController) {
}
}
κ·Έλ¦¬κ³ κ·Έκ²μ μ μλν©λλ€ :)
κ·Έλ¬λ ionicμ ν(κΈ°λ³Έκ°)μ μ¬μ©νκ³ μ€ν¬λ‘€ 컨ν
μ΄λμ display: none
λ₯Ό μΆκ°νκΈ° λλ¬Έμ μ΄λ―Έμ§κ° μ²μμ λ·°ν¬νΈμ μλμ§ μ¬λΆλ₯Ό κ²°μ νλ κ²μ΄ κ±°μ λΆκ°λ₯ν©λλ€. κ΅μ°¨ κ΄μ°°μ μ κ°μ κ²μ μ¬μ©νλ κ²μ΄ μ’μ§λ§ Chromeμμλ§ μλνλ©° iOSλ₯Ό λμμΌλ‘ νλ κ²½μ° Safariλ₯Ό μ¬μ©ν κ²μ
λλ€.
κ·Έλ¬λ ν κ°μ§ ν΄κ²°μ±
μ μ΄λ―Έμ§κ° μ¨κ²¨μ Έ μλμ§ νμΈνλ κ²μ
λλ€(μ: el.offsetParent === null
). κ·Έλ¬λ μ΄λ―Έμ§κ° λ€μ νμλλ©΄ ng2-lazyload-image
λ μλ¦Όμ μμ νμ§ μμΌλ©° μ΄λ―Έμ§κ° λ·°ν¬νΈμ μμΌλ©΄ μ¬μ©μκ° μ€ν¬λ‘€μ μμνκΈ° μ μλ μ΄λ―Έμ§κ° νμλμ§ μμ΅λλ€. κ·Έλ¬λ *ngIf
μ¬μ©ν μ μμ΅λλ€.
<img
*ngIf="container._scroll._el.offsetParent !== null"
style="height: 1099px;"
[src]="defaultImage"
[lazyLoad]="image"
[offset]="offset"
[scrollTarget]="container._scroll._el">
κ·Έλ¬λ κ·Έκ²μ μ’μ§ μμ 보μ λλ€ :/
λ°λΌμ (λ μ΄μμμ λ°λΌ) ionic μ±μμ ng2-lazyload-image
λ₯Ό μ¬μ©νκ±°λ μ¬μ©νμ§ λͺ»ν μλ μμ§λ§ λ°νμ μ€λ₯λ λ°μ νμ§ μμμΌ ν©λλ€.
μ€νλ₯Ό λμ΅λλ€.
[lazyload]κ° μλλΌ [lazyLoad]μ
λλ€.
건배 :)
κ·Έκ²μ μ°½νΌν μ λλ‘ κ°λ¨νκ² λ€λ¦½λλ€.
rc1μΌλ‘ μ
κ·Έλ μ΄λν΄μ μ¬μ©ν΄λ³΄κ² μ΅λλ€. κ°μ¬ ν΄μ.
2016λ 10μ 17μΌ μμμΌ μ€ν 1μ 37λΆμ Stan Faas [email protected]μ΄ λ€μκ³Ό κ°μ΄ μΌμ΅λλ€.
μ€νλ₯Ό λμ΅λλ€.
[lazyload]κ° μλλΌ [lazyLoad]μ λλ€.건배 :)
β
μ€λ λλ₯Ό μμ±νκΈ° λλ¬Έμ μ΄ λ©μμ§λ₯Ό λ°λ κ²μ λλ€.
μ΄ μ΄λ©μΌμ μ§μ λ΅μ₯νκ³ GitHubμμ νμΈνμΈμ.
https://github.com/tjoskar/ng2-lazyload-image/issues/37#issuecomment -254195387,
λλ μ€λ λ μμκ±°
https://github.com/notifications/unsubscribe-auth/APPh0par6NR7EA3DA1GbibncX8gCb2YRks5q02wTgaJpZM4J5EjU
.
@StanFaas , μ’μ μΊμΉ!
κ°μ μ€λ₯κ° λ°μν©λλ€ μ΄λ»κ² ν΄κ²°ν μ μμ΅λκΉ?
κ°μ₯ μ μ©ν λκΈ
μ€νλ₯Ό λμ΅λλ€.
[lazyload]κ° μλλΌ [lazyLoad]μ λλ€.
건배 :)