Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4bcf991

Browse files
fix(): highlight active section
1 parent ac503bd commit 4bcf991

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

‎src/app/homepage/header/header.component.scss‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
@import "../../../scss/variables.scss";
2-
@import "../../../scss/utils.scss";
1+
@import '../../../scss/variables.scss';
2+
@import '../../../scss/utils.scss';
33

44
:host {
55
background: $black-color;
@@ -240,7 +240,7 @@ header {
240240
}
241241

242242
&::after {
243-
content: "";
243+
content: '';
244244
display: block;
245245
background: #246081;
246246
height: 2px;
@@ -293,7 +293,7 @@ header {
293293
span,
294294
&::after,
295295
&::before {
296-
content: "";
296+
content: '';
297297
background: #fff;
298298
display: block;
299299
height: 2px;
@@ -331,7 +331,7 @@ header {
331331
border-bottom: 2px solid #414141;
332332
padding: 5px 20px 5px 28px;
333333
color: #fff;
334-
font-family: "Source Sans Pro", "Helvetica Neue", sans-serif;
334+
font-family: 'Source Sans Pro', 'Helvetica Neue', sans-serif;
335335
font-size: 14px;
336336
outline: 0 !important;
337337
transition: all 90ms ease-in-out;
@@ -365,7 +365,7 @@ header {
365365

366366
&::after,
367367
&::before {
368-
content: "";
368+
content: '';
369369
background: $red-color;
370370
display: block;
371371
height: 2px;

‎src/app/shared/components/toc/toc.component.html‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
*ngFor="let item of headings; trackBy: trackById; let index = index"
55
[attr.id]="item.id"
66
[class.current]="index === activeId"
7+
>
8+
<a
9+
href="{{ currentURL() }}#{{ item.elementRef.id }}"
10+
(click)="navigateToAnchor($event, item.elementRef)"
711
>
8-
<a href="{{ currentURL() }}#{{ item.elementRef.id }}">
912
{{ item.textContent }}
1013
</a>
1114
</li>

‎src/app/shared/components/toc/toc.component.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,17 @@ export class TocComponent implements OnInit, OnDestroy, OnChanges {
101101
.subscribe(() => this.init());
102102
}
103103

104+
navigateToAnchor($event: MouseEvent, elementRef: HTMLElement) {
105+
if (elementRef) {
106+
$event.preventDefault();
107+
elementRef.scrollIntoView({
108+
behavior: 'smooth',
109+
block: 'start',
110+
});
111+
this.findCurrentHeading();
112+
}
113+
}
114+
104115
findCurrentHeading() {
105116
const marginOffset = 15;
106117
const selectHeading = (i: number) => {

0 commit comments

Comments
 (0)