-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.component.ts
69 lines (59 loc) · 1.56 KB
/
app.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import {
ChangeDetectorRef,
Component,
ElementRef,
QueryList,
ViewChild,
ViewChildren
} from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent {
markup: string;
typescript: string;
style: string;
@ViewChildren('percentages') percentages: QueryList<ElementRef>;
@ViewChildren('sections') sections: QueryList<ElementRef>;
@ViewChild('btnGroup', { static: false }) btnGroup: ElementRef;
@ViewChild('bar', { static: false }) bar: ElementRef;
// SET TO ANY AMOUNT!
sectionLength = 3;
barLinkWidth = 0;
currentSection = 0;
Math: any;
constructor(
private _cd: ChangeDetectorRef,
) {
this.Math = Math;
}
ngAfterViewInit() {
this._cd.detectChanges();
this.barLinkWidth = 100 / this.sections.length;
this.bar.nativeElement.setAttribute(
'style',
'width:' + this.barLinkWidth + '%'
);
this.btnGroup.nativeElement.style.gridTemplateColumns =
'repeat(' + this.sectionLength + ', auto)';
}
navigate(sectionIndex: number) {
this.currentSection = sectionIndex;
this.bar.nativeElement.style.width =
this.barLinkWidth * (sectionIndex + 1) + '%';
}
showProgressBar() {
this.bar.nativeElement.style.height = '22px';
this.percentages.forEach((val) => {
val.nativeElement.style.opacity = 1;
});
}
hideProgressBar() {
this.bar.nativeElement.style.height = '3px';
this.percentages.forEach((val) => {
val.nativeElement.style.opacity = 0;
});
}
}