// ...
@Component({
// ...
})
export class AlbumComponent implements OnInit {
// ...
preloadedPhotos: HTMLImageElement[]; // 🅰
// ...
ngOnInit() {
// ...
// 🅱
this.preloadedPhotos = new Array<HTMLImageElement>(this.album.photos.length);
this.preloadPhoto(-1);
this.preloadPhoto(0);
this.preloadPhoto(1);
}
preloadPhoto(idx) { // 🅲
if (!this.preloadedPhotos[idx]) {
this.preloadedPhotos[idx] = new Image();
this.preloadedPhotos[idx].src = this.photosUrl + this.album.photos[idx];
}
}
slide(offset) {
// ...
this.preloadPhoto(this.current + offset); // 🅳
}
}