Event scroll Angular 2+
Angular 2+
import { Component, HostListener, Inject, NgModule, OnInit } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { DOCUMENT } from '@angular/platform-browser'; import { WINDOW } from "./services/window.service"; @Component({ selector: 'my-app', templateUrl: './app.component.html', styleUrls: ['./app.component.scss'] }) export class AppComponent { constructor( @Inject(DOCUMENT) private document: Document, @Inject(WINDOW) private window: Window ) {} @HostListener("window:scroll", []) onWindowScroll() { const offset = this.window.pageYOffset || this.document.documentElement.scrollTop || this.document.body.scrollTop || 0; console.log(offset); } }
0 nhận xét:
Post a Comment