Project

General

Profile

1
import {AfterContentInit, Component, ContentChildren, Input, OnInit, QueryList} from "@angular/core";
2
import {SlideComponent} from "./slide.component";
3

    
4
@Component({
5
  selector: 'fp-slider',
6
  template: `
7
    <div class="menu">
8
      <img class="logo" *ngIf="logoURL" [src]="logoURL">
9
      <a *ngIf="state > 1" class="previous" (click)="onClick(state - 1)">
10
        <svg xmlns="http://www.w3.org/2000/svg" width="17.155" height="17.155" viewBox="0 0 17.155 17.155">
11
          <g id="Group_3053" data-name="Group 3053" transform="translate(0)">
12
            <path id="arrow-down-left2"
13
                  d="M10.405,11.834,2.022,3.451V7.076A1.011,1.011,0,0,1,0,7.076V1.011A1.009,1.009,0,0,1,1.011,0H7.076a1.011,1.011,0,1,1,0,2.022H3.451l8.383,8.383a1.011,1.011,0,1,1-1.429,1.429h0Z"
14
                  transform="translate(8.578 0) rotate(45)" fill="#e95420"/>
15
          </g>
16
        </svg>
17
      </a>
18
      <nav>
19
        <ul>
20
          <li *ngFor="let slide of slides.toArray();let i=index" [class.uk-active]="i === (state - 1)">
21
            <a (click)="onClick(i + 1)"></a>
22
          </li>
23
        </ul>
24
      </nav>
25
      <a *ngIf="state < slides.length" class="next" (click)="onClick(state + 1)">
26
        <svg xmlns="http://www.w3.org/2000/svg" width="17.155" height="17.155" viewBox="0 0 17.155 17.155">
27
          <g id="Group_2442" data-name="Group 2442" transform="translate(-1221 -675)">
28
            <path id="arrow-down-left2"
29
                  d="M14.405,4.3,6.022,12.68V9.055A1.011,1.011,0,0,0,4,9.055V15.12a1.009,1.009,0,0,0,1.011,1.01h6.065a1.011,1.011,0,1,0,0-2.022H7.451l8.383-8.383A1.011,1.011,0,0,0,14.405,4.3h0Z"
30
                  transform="translate(1215.343 683.578) rotate(-45)" fill="#e95420"/>
31
          </g>
32
        </svg>
33
      </a>
34
    </div>
35
    <section (wheel)="onWheel($event)">
36
      <ng-content></ng-content>
37
    </section>`,
38
  styleUrls: ['full-page-slider.component.css']
39
})
40
export class FullPageSliderComponent implements AfterContentInit {
41
  
42
  @ContentChildren(SlideComponent) slides: QueryList<SlideComponent>;
43
  @Input()
44
  public initSlide = 1;
45
  @Input()
46
  public logoURL;
47
  public animate: boolean = false;
48
  public state = 0;
49
  
50
  ngAfterContentInit() {
51
    this.state = this.initSlide;
52
    this.setSlides(this.state);
53
  }
54
  
55
  setSlides(state = 1) {
56
    this.slides.forEach((slide, index) => {
57
      slide.state = state;
58
      slide.y = -50 + (index + 1) * 200 - state * 200;
59
    });
60
  }
61
  
62
  onWheel(event) {
63
    if (!this.animate) {
64
      this.animate = true;
65
      if (event.deltaY > 0 && (this.state < this.slides.length)) {
66
        this.state++;
67
        this.setSlides(this.state);
68
        setTimeout(() => {
69
          this.animate = false;
70
        }, 500);
71
      } else if (event.deltaY < 0 && (this.state !== 1)) {
72
        this.state--;
73
        this.setSlides(this.state);
74
        setTimeout(() => {
75
          this.animate = false;
76
        }, 500);
77
      } else {
78
        this.animate = false;
79
      }
80
    }
81
  }
82
  
83
  public onClick(index: number) {
84
    if (!this.animate) {
85
      this.animate = true;
86
      this.state = index;
87
      this.setSlides(this.state);
88
      setTimeout(() => {
89
        this.animate = false;
90
      }, 500);
91
    }
92
  }
93
}
(3-3/5)