From b310eb4e64c1ad5192ec6863b42207e7693b554e Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Mon, 15 Jun 2020 19:02:44 +0000 Subject: [PATCH] [Library | Trunk]: Create full page slider component git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@58919 d315682c-612b-4755-9ff5-7f18f6832af3 --- utils/full-page-slider/animation.ts | 10 ++++ .../full-page-slider.component.css | 8 +++ .../full-page-slider.component.ts | 51 +++++++++++++++++++ .../full-page-slider.module.ts | 13 +++++ utils/full-page-slider/slide.component.ts | 27 ++++++++++ 5 files changed, 109 insertions(+) create mode 100644 utils/full-page-slider/animation.ts create mode 100644 utils/full-page-slider/full-page-slider.component.css create mode 100644 utils/full-page-slider/full-page-slider.component.ts create mode 100644 utils/full-page-slider/full-page-slider.module.ts create mode 100644 utils/full-page-slider/slide.component.ts diff --git a/utils/full-page-slider/animation.ts b/utils/full-page-slider/animation.ts new file mode 100644 index 00000000..e97a9552 --- /dev/null +++ b/utils/full-page-slider/animation.ts @@ -0,0 +1,10 @@ +import {animate, state, style, transition, trigger} from "@angular/animations"; + +export const animation = trigger('state', [ + state('*', style({ + transform: 'translate(-50%, {{y}}%)' + }), {params: {y: -50}}), + transition('* => *', [ + animate('1s') + ]) +]); diff --git a/utils/full-page-slider/full-page-slider.component.css b/utils/full-page-slider/full-page-slider.component.css new file mode 100644 index 00000000..97f509a8 --- /dev/null +++ b/utils/full-page-slider/full-page-slider.component.css @@ -0,0 +1,8 @@ +section { + position: fixed; + top:10%; + left: 0; + height: 90%; + width: 100%; + overflow: hidden; +} diff --git a/utils/full-page-slider/full-page-slider.component.ts b/utils/full-page-slider/full-page-slider.component.ts new file mode 100644 index 00000000..938949a8 --- /dev/null +++ b/utils/full-page-slider/full-page-slider.component.ts @@ -0,0 +1,51 @@ +import {AfterContentInit, Component, ContentChildren, QueryList} from "@angular/core"; +import {SlideComponent} from "./slide.component"; + +@Component({ + selector: 'fp-slider', + template: ` +
+ +
`, + styleUrls: ['full-page-slider.component.css'] +}) +export class FullPageSliderComponent implements AfterContentInit { + + @ContentChildren(SlideComponent) slides: QueryList; + + public animate: boolean = false; + public state = 0; + + ngAfterContentInit() { + this.setSlides(); + this.state = 1; + } + + 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 < this.slides.length)) { + this.state++; + this.setSlides(this.state); + setTimeout(() => { + this.animate = false; + }, 1000); + } else if (event.deltaY < 0 && (this.state !== 1)) { + this.state--; + this.setSlides(this.state); + setTimeout(() => { + this.animate = false; + }, 1000); + } else { + this.animate = false; + } + } + } +} diff --git a/utils/full-page-slider/full-page-slider.module.ts b/utils/full-page-slider/full-page-slider.module.ts new file mode 100644 index 00000000..a9366168 --- /dev/null +++ b/utils/full-page-slider/full-page-slider.module.ts @@ -0,0 +1,13 @@ +import {NgModule} from "@angular/core"; +import {CommonModule} from "@angular/common"; +import {FullPageSliderComponent} from "./full-page-slider.component"; +import {SlideComponent} from "./slide.component"; + +@NgModule({ + imports: [CommonModule], + declarations: [FullPageSliderComponent, SlideComponent], + exports: [FullPageSliderComponent, SlideComponent], +}) +export class FullPageSliderModule { + +} diff --git a/utils/full-page-slider/slide.component.ts b/utils/full-page-slider/slide.component.ts new file mode 100644 index 00000000..586e9928 --- /dev/null +++ b/utils/full-page-slider/slide.component.ts @@ -0,0 +1,27 @@ +import {Component} from "@angular/core"; +import {animation} from "./animation"; +import {transition, trigger} from "@angular/animations"; + +@Component({ + selector: 'slide', + template: ` +
+
+ +
+
+ `, + animations: [animation, + trigger( + "blockInitialRenderAnimation", + [ + transition( ":enter", [] ) + ] + )] +}) +export class SlideComponent { + state: number = 1 + y: number = -50; + medium: boolean = true; +}