📜  滚动,位置 - TypeScript 代码示例

📅  最后修改于: 2022-03-11 14:48:12.190000             🧑  作者: Mango

代码示例1
import { HostListener } from '@angular/core';

@ViewChild('curtain') divCurtain: ElementRef;

export class ComponentX {
    @HostListener('window:scroll', ['$event']) onScrollEvent($event) {
        console.log(window.pageYOffset);
        this.divCurtain.nativeElement.style.top = window.pageYOffset.toString().concat('px');
    }

    ngOnInit(): void { }
}