Project

General

Profile

« Previous | Next » 

Revision 60850

Fixed the scrolling and fragment handling

View differences:

methodology.component.ts
1
import { Component, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core';
2
import { ActivatedRoute } from '@angular/router';
3
import { Subscription } from 'rxjs';
1
import { Component, ViewEncapsulation } from '@angular/core';
4 2

  
5 3
@Component({
6 4
  selector: 'app-methodology',
......
9 7
  encapsulation: ViewEncapsulation.None
10 8
})
11 9

  
12
export class MethodologyPageComponent implements OnInit, OnDestroy {
13

  
14
  private subscriptions: any[] = [];
15

  
16
  constructor(private route: ActivatedRoute) {
17
  }
18

  
19
  ngOnInit(): void {
20
    this.subscriptions.push(this.route.fragment.subscribe(fragment => {
21
      setTimeout(() => {
22
        this.goTo(fragment);
23
      }, 100);
24
    }));
25
  }
26

  
27
  goTo(id: string) {
28
    const yOffset = -100;
29
    const element = document.getElementById(id);
30
    if (element) {
31
      const y = element.getBoundingClientRect().top + window.pageYOffset + yOffset;
32
      window.scrollTo({top: y, behavior: 'smooth'});
33
    }
34
  }
35

  
36
  ngOnDestroy(): void {
37
    this.subscriptions.forEach(subscription => {
38
      if (subscription instanceof Subscription) {
39
        subscription.unsubscribe();
40
      }
41
    });
42
  }
10
export class MethodologyPageComponent {
43 11
}

Also available in: Unified diff