I want to create a sliding background image much like what you see at this site: https://chucklefish.org/. Notice how every few seconds a new background image slides in.
I want to do this using Angular's animation module.
Typescript
import { Component, HostBinding, OnInit } from '@angular/core';
import {
trigger,
state,
style,
animate,
transition,
// ...
} from '@angular/animations';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css'],
animations: [
trigger('slidingPictures',[
state('game1',style({
background:"url(../assets/images/game1.jpg)"
})),
state('game2',style({
background:"url(../assets/images/game2.png)"
})),
state('game3',style({
background:"url(../assets/images/game3.jpg)"
})),
transition('game1=>game2',[
animate('1s',
style (
{
transform: 'translateX(-100%)',
}
))
]),
transition('game2=>game3',[
animate('1s',style({
transform: 'translateX(-100%)',
}))
]),
transition('game3=>game1',[
animate('1s',style({transform: 'translateX(-100%)'}))
])
]),
]
})
export class HomeComponent implements OnInit {
game:string;
gameIndex:number;
games:string[];
constructor() {
this.gameIndex = 0;
this.games = ['game1','game2','game3'];
this.game = this.games[this.gameIndex];
setInterval(() => this.rotatingBackground(), 5000);
}
ngOnInit() {
}
rotatingBackground():any {
console.log(this.gameIndex);
this.game = this.games[this.gameIndex];
this.gameIndex++;
if(this.gameIndex >= this.games.length) {
this.gameIndex = 0;
}
console.log(this.game);
}
}
Right now how code works is that there are images that slide to the left but while they slide to the left there is a white background. I would like the new image to slide in from the right at the same time.