import {AfterContentInit, Component, ContentChildren, Input, OnInit, QueryList} from "@angular/core"; import {SlideComponent} from "./slide.component"; import {BehaviorSubject, Observable} from 'rxjs'; @Component({ selector: 'fp-slider', template: `
`, styleUrls: ['full-page-slider.component.css'] }) export class FullPageSliderComponent implements AfterContentInit { @ContentChildren(SlideComponent) slides: QueryList; @Input() public initSlide = 1; @Input() public logoURL; @Input() topBar: string = null; @Input() hasFooter: boolean = null; @Input() footerClass: string; public animate: boolean = false; public state: BehaviorSubject = new BehaviorSubject(0); ngAfterContentInit() { this.state.next(this.initSlide); this.setSlides(this.state.value); } setSlides(state = 1) { this.slides.forEach((slide, index) => { slide.state = state; slide.y = -50 + (index + 1) * 200 - state * 200; }); } onWheel(event) { if (!this.animate) { this.animate = true; if (event.deltaY > 0 && (this.state.value < this.slides.length)) { this.state.next(+this.state.value + 1); this.setSlides(this.state.value); setTimeout(() => { this.animate = false; }, 500); } else if (event.deltaY < 0 && (this.state.value !== 1)) { this.state.next(this.state.value - 1); this.setSlides(this.state.value); setTimeout(() => { this.animate = false; }, 500); } else { this.animate = false; } } } public onClick(index: number) { if (!this.animate) { this.animate = true; this.state.next(index); this.setSlides(this.state.value); setTimeout(() => { this.animate = false; }, 500); } } public get stateValue() { return this.state.value; } public get stateAsObservable(): Observable { return this.state.asObservable(); } }