Uses reusable animation and scroll method
This commit is contained in:
parent
5c72ece46a
commit
cda78c66e4
|
@ -1,38 +1,14 @@
|
|||
import {Component, ElementRef, HostListener, OnInit} from '@angular/core';
|
||||
import {ApiService} from '../api.service';
|
||||
import {Capability} from '../interfaces';
|
||||
import {animate, state, style, transition, trigger, useAnimation} from '@angular/animations';
|
||||
import {fadeIn, fadeOut} from '../animation';
|
||||
import {isEven} from '../util';
|
||||
import {animations} from '../animation';
|
||||
import {getScrollState, isEven} from '../util';
|
||||
|
||||
@Component({
|
||||
selector: 'app-about-us',
|
||||
templateUrl: './about-us.component.html',
|
||||
styleUrls: ['./about-us.component.scss'],
|
||||
animations: [
|
||||
trigger('fadeInOut', [
|
||||
transition('void <=> *', useAnimation(fadeIn)),
|
||||
transition('* <=> void', useAnimation(fadeOut))
|
||||
]),
|
||||
trigger('scrollAnimation', [
|
||||
state(
|
||||
'show',
|
||||
style({
|
||||
opacity: 1,
|
||||
zIndex: 0
|
||||
})
|
||||
),
|
||||
state(
|
||||
'hide',
|
||||
style({
|
||||
opacity: 0,
|
||||
zIndex: 0
|
||||
})
|
||||
),
|
||||
transition('show => hide', animate('700ms ease-out')),
|
||||
transition('hide => show', animate('700ms ease-in'))
|
||||
])
|
||||
]
|
||||
animations: animations
|
||||
})
|
||||
export class AboutUsComponent implements OnInit {
|
||||
capabilities: Capability[];
|
||||
|
@ -48,9 +24,6 @@ export class AboutUsComponent implements OnInit {
|
|||
|
||||
@HostListener('window:scroll', ['$event'])
|
||||
checkScroll() {
|
||||
const hOffset = window.innerHeight / 2;
|
||||
const componentPosition = this.el.nativeElement.offsetTop;
|
||||
const scrollPosition = window.pageYOffset + hOffset;
|
||||
this.state = scrollPosition >= componentPosition ? 'show' : 'hide';
|
||||
this.state = getScrollState(this.el);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,36 +7,14 @@ import {
|
|||
trigger,
|
||||
useAnimation
|
||||
} from '@angular/animations';
|
||||
import { fadeIn, fadeOut } from '../animation';
|
||||
import {animations, fadeIn, fadeOut} from '../animation';
|
||||
import {getScrollState} from '../util';
|
||||
|
||||
@Component({
|
||||
selector: 'app-welcome',
|
||||
templateUrl: './welcome.component.html',
|
||||
styleUrls: ['./welcome.component.scss'],
|
||||
animations: [
|
||||
trigger('fadeInOut', [
|
||||
transition('void <=> *', useAnimation(fadeIn)),
|
||||
transition('* <=> void', useAnimation(fadeOut))
|
||||
]),
|
||||
trigger('scrollAnimation', [
|
||||
state(
|
||||
'show',
|
||||
style({
|
||||
opacity: 1,
|
||||
zIndex: 0
|
||||
})
|
||||
),
|
||||
state(
|
||||
'hide',
|
||||
style({
|
||||
opacity: 0,
|
||||
zIndex: 0
|
||||
})
|
||||
),
|
||||
transition('show => hide', animate('700ms ease-out')),
|
||||
transition('hide => show', animate('700ms ease-in'))
|
||||
])
|
||||
]
|
||||
animations: animations
|
||||
})
|
||||
export class WelcomeComponent implements OnInit {
|
||||
state = 'hide';
|
||||
|
@ -47,9 +25,6 @@ export class WelcomeComponent implements OnInit {
|
|||
|
||||
@HostListener('window:scroll', ['$event'])
|
||||
checkScroll() {
|
||||
const hOffset = window.innerHeight / 2;
|
||||
const componentPosition = this.el.nativeElement.offsetTop;
|
||||
const scrollPosition = window.pageYOffset + hOffset;
|
||||
this.state = scrollPosition >= componentPosition ? 'show' : 'hide';
|
||||
this.state = getScrollState(this.el);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue