html - Angular 2 show and hide scroll button -
i have button shows on right corner when make first scroll down move. want make button disappear after scroll on page. how can this? far, typescript function track($event:any){} looks this:
import { component } '@angular/core'; @component({ host: {'(window:scroll)': 'track($event)'} }) export class directsearchcomponent{ showscrollbutton:boolean=false; beginy: any; constructor() {} track($event:any) { console.debug("scroll event", $event); if (this.beginy == undefined || this.beginy != null) { if (this.beginy > $event.scrolly) { this.showscrollbutton = false; } else { this.showscrollbutton = true; } } else { this.beginy = $event.scrolly; this.showscrollbutton = true; } } }
and html code button looks this:
<a href="#" class="scrollup"> <button *ngif="showscrollbutton" type="button" class="btn btn-primary btn-block pull-right" style="position: fixed; bottom: 10px; right: 51px; width:3%; overflow:auto;"> <i class="glyphicon glyphicon-chevron-up" ></i> </button> </a>
thanks in advance!
looks this.beginy not being initialized properly.
import ngoninit , in ngoninit method, set...
this.beginy = document.documentelement.scrolltop || document.body.scrolltop;
this should initialize variable initial page scroll value.
Comments
Post a Comment