File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed
apps/daffio/src/app/docs/components/scroll-to-top Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -2,12 +2,14 @@ import { DOCUMENT } from '@angular/common';
22import {
33 ChangeDetectionStrategy ,
44 Component ,
5- HostListener ,
65 Inject ,
6+ ChangeDetectorRef ,
77} from '@angular/core' ;
88import { FaIconComponent } from '@fortawesome/angular-fontawesome' ;
99import { faArrowUp } from '@fortawesome/free-solid-svg-icons' ;
1010
11+ import { debounce } from '@daffodil/core' ;
12+
1113@Component ( {
1214 selector : 'daffio-docs-scroll-to-top' ,
1315 templateUrl : './scroll-to-top.component.html' ,
@@ -16,15 +18,21 @@ import { faArrowUp } from '@fortawesome/free-solid-svg-icons';
1618 imports : [
1719 FaIconComponent ,
1820 ] ,
21+ host : {
22+ '(document:scroll)' : 'onScroll()' ,
23+ } ,
1924} )
2025
2126export class DaffioDocsScrollToTopComponent {
2227 showButton = false ;
2328 faArrowUp = faArrowUp ;
2429
25- constructor ( @Inject ( DOCUMENT ) private document : Document ) { }
30+ constructor (
31+ @Inject ( DOCUMENT ) private document : Document ,
32+ private cdr : ChangeDetectorRef ,
33+ ) { }
2634
27- @HostListener ( 'document:scroll' )
35+ @debounce ( 100 )
2836 onScroll ( ) {
2937 const currentScrollPosition = this . document . documentElement . scrollTop || this . document . body . scrollTop ;
3038
@@ -33,10 +41,14 @@ export class DaffioDocsScrollToTopComponent {
3341 } else {
3442 this . showButton = false ;
3543 }
44+
45+ this . cdr . markForCheck ( ) ;
3646 }
3747
3848 scrollToTop ( ) {
3949 this . document . documentElement . scrollTop = 0 ;
4050 this . document . body . scrollTop = 0 ;
51+
52+ this . showButton = false ;
4153 }
4254}
You can’t perform that action at this time.
0 commit comments