Skip to content

Commit

Permalink
Preloading background images avoiding 'blinking'.
Browse files Browse the repository at this point in the history
- Preloading the boundaries images related to the current position in order to avoid the 'blinking' of the background while navigating.
  • Loading branch information
guilhermeborgesbastos committed May 22, 2020
1 parent 08aeb5b commit f428156
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/app/experience/experience.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,20 @@ export class ExperienceComponent implements OnInit {
this.experiencesOrdered.sort(this.sortService.sort('position', 'desc'));
this.backgroundUrl = this.retrieveBackgroundUrl();
this.updateMobileNavigationView();
this.preloadBounderyImages(experiences.map(xp => xp.backgroundUrl));
});
}

createListSelector(position: number): string {
// Preloads the boundaries images related to the current position in order to avoid the 'blinking' of the background while navigating.
private preloadBounderyImages(images: string[]) {
images.forEach(function (image, i) {
const preloadImages = new Array();
preloadImages[i] = new Image();
preloadImages[i].src = image;
});
}

private createListSelector(position: number): string {
return `li[id="${position}"]`;
}

Expand Down Expand Up @@ -116,11 +126,11 @@ export class ExperienceComponent implements OnInit {
}
}

retrieveBackgroundUrl(): string {
private retrieveBackgroundUrl(): string {
return this.experiences[this.currentPosition - 1].backgroundUrl;
}

updateMobileNavigationView() {
private updateMobileNavigationView() {
this.previousYear =
this.experiences[this.currentPosition - 2]?.startAt || this.experiences[this.currentPosition - 1].startAt;
this.currentYear =
Expand Down

0 comments on commit f428156

Please sign in to comment.