Skip to content

Commit a73d97b

Browse files
committed
Fix idle state styling. Reuse anim ms timing.
1 parent 82cb684 commit a73d97b

File tree

3 files changed

+32
-28
lines changed

3 files changed

+32
-28
lines changed

src/app/public/ngx-scroll-top.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
(click)="scrollTop()"
44
[class.fade-in]="fadeState() === 'fading-in'"
55
[class.fade-out]="fadeState() === 'fading-out'"
6+
[class.idle]="fadeState() === 'idle'"
67
[style.background-color]="backgroundColor()"
78
aria-label="Scroll to top"
89
>

src/app/public/ngx-scroll-top.component.scss

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -62,28 +62,6 @@ svg.default-content {
6262
top: 0;
6363
}
6464

65-
.fade-in {
66-
animation: fadeIn 0.2s ease-in forwards;
67-
}
68-
69-
.fade-out {
70-
animation: fadeOut 0.2s ease-out forwards;
71-
}
72-
73-
@keyframes fadeIn {
74-
from {
75-
opacity: 0;
76-
}
77-
to {
78-
opacity: 1;
79-
}
80-
}
81-
82-
@keyframes fadeOut {
83-
from {
84-
opacity: 1;
85-
}
86-
to {
87-
opacity: 0;
88-
}
65+
button.idle {
66+
opacity: 0;
8967
}

src/app/public/ngx-scroll-top.component.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,38 @@ import {
88
signal,
99
} from '@angular/core';
1010

11+
const animationMs = 200;
12+
1113
@Component({
1214
selector: 'ngx-scroll-top',
1315
templateUrl: './ngx-scroll-top.component.html',
1416
styleUrl: './ngx-scroll-top.component.scss',
15-
imports: [],
16-
standalone: true,
17+
styles: [
18+
`
19+
.fade-in {
20+
animation: fadeIn ${animationMs}ms ease-in forwards;
21+
}
22+
.fade-out {
23+
animation: fadeOut ${animationMs}ms ease-out forwards;
24+
}
25+
@keyframes fadeIn {
26+
from {
27+
opacity: 0;
28+
}
29+
to {
30+
opacity: 1;
31+
}
32+
}
33+
@keyframes fadeOut {
34+
from {
35+
opacity: 1;
36+
}
37+
to {
38+
opacity: 0;
39+
}
40+
}
41+
`,
42+
],
1743
})
1844
export class NgxScrollTopComponent implements OnInit, OnDestroy {
1945
/**
@@ -128,7 +154,7 @@ export class NgxScrollTopComponent implements OnInit, OnDestroy {
128154
private readonly defaultPadding = '16px';
129155

130156
/** Duration for fade-in/fade-out animations. */
131-
private readonly fadeDuration = 200;
157+
private readonly fadeDuration = animationMs;
132158

133159
/** Timeout reference for fade completion. */
134160
private fadeTimeout?: ReturnType<typeof setTimeout>;
@@ -239,7 +265,6 @@ export class NgxScrollTopComponent implements OnInit, OnDestroy {
239265
// Schedule fade-in with animation frame
240266
this.animationFrameId = requestAnimationFrame(() => {
241267
this.fadeState.set('fading-in');
242-
this.animationFrameId = undefined;
243268
});
244269
}
245270
// Fade out

0 commit comments

Comments
 (0)