I am trying to create ionic app with background image sliding based on timer on home page.
facing issue with slow loading images.
home.ts
import { Component, Input, ViewChild } from ‘@angular/core’;
import { NavController, Content } from ‘ionic-angular’;
import { BackgroundService } from ‘…/…/services’;
import { HttpErrorResponse } from ‘@angular/common/http’;
@Component({
selector: ‘page-home’,
templateUrl: ‘home.html’
})
export class HomePage {
@ViewChild(Content) private content: Content;
private displayTime: number;
private basePath: string;
private transitionTime: string;
private images: string[];
private task: number;
@Input(‘header’)
header_data:any;
constructor(public navCtrl: NavController, private backgroundService: BackgroundService) {
this.header_data = {ismenu:true,ishome:false,title:“Custom Home”};
}
public ngOnInit() {
this.backgroundService.getConfigObjectFromJson().subscribe(
data=> {
let configObject = data.config;
this.displayTime = configObject.HM_BKG_IMG_DISPLAY_TIME;
this.basePath = configObject.IMG_BASE_PATH;
this.transitionTime = configObject.HM_BKG_IMG_TRANSITION_DURATION;
this.images = configObject.HM_BKG_IMAGES;
this.startImageSlideShow();
},
(error: HttpErrorResponse) => {
console.log(error.message);
}
)
}
private startImageSlideShow() {
let index = 0;
this.content.setElementStyle(‘transition-duration’, this.transitionTime);
this.task = window.setInterval(()=> {
console.log(‘Before image set *************’ + this.images[index]);
this.content.setElementStyle(‘background-image’, ‘url(’+ this.basePath + this.images[index] +’)’);
index++;
if(index >= this.images.length) {
index = 0;
}
console.log(‘After image set *************’);
},this.displayTime);
}
public ngOnDestroy() {
window.clearInterval(this.task);
}
}
home.scss
page-home {
ion-content {
background-size: 100% 100%;
-webkit-transition: background-image 1s ease-in-out, -webkit-transform 200ms ease;
transition: background-image 1s ease-in-out, transform 200ms ease;
background-repeat: no-repeat;
background-position: center center;
background-color: transparent;
}
}
Please suggest me how to resolve the issue