forked from Cloud-CV/EvalAI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Frontend_V2: Add lazy loading for images(Cloud-CV#3571)
* add lazy load for images * add new line Co-authored-by: Rishabh Jain <[email protected]>
- Loading branch information
1 parent
94f74f9
commit 59b961f
Showing
3 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { AfterViewInit, Directive, ElementRef, HostBinding, Input } from '@angular/core'; | ||
|
||
@Directive({ | ||
selector: 'img[appLazyLoadImage]' | ||
}) | ||
|
||
export class LazyImageDirective implements AfterViewInit { | ||
|
||
@HostBinding('attr.src') srcAttribute = null; | ||
|
||
@Input() src: string; | ||
|
||
constructor(private el: ElementRef) {} | ||
|
||
ngAfterViewInit() { | ||
if(window && 'IntersectionObserver' in window) { | ||
const obs = new IntersectionObserver(entries => { | ||
entries.forEach(({ isIntersecting }) => { | ||
if (isIntersecting) { | ||
this.srcAttribute = this.src; | ||
obs.unobserve(this.el.nativeElement); | ||
} | ||
}); | ||
}); | ||
obs.observe(this.el.nativeElement); | ||
} | ||
else { | ||
this.srcAttribute = this.src; | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...2/src/app/components/publiclists/challengelist/challengecard/challengecard.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters