相关疑难解决方法(0)

Angular 4 @HostListener窗口滚动事件奇怪地在Firefox中不起作用

@HostListener('window:scroll', [])在Angular 4应用程序中使用,以便在滚动时向标题添加其他类.它在Chrome中运行良好,但我注意到在Firefox 54.0(我认为它是最新的当前版本)中没有添加该类,它根本不执行onWindowScroll()方法.可能是什么原因?

这是代码的一部分和Plunker演示(顺便说一句,在Chrome中也可以正常工作但在Mozilla中不行):

public isScrolled = false;
constructor(@Inject(DOCUMENT) private document: any) {}
@HostListener('window:scroll', [])
onWindowScroll() {
    const number = this.document.body.scrollTop;
    if (number > 150) {
        this.isScrolled = true;
    } else if (this.isScrolled && number < 10) {
        this.isScrolled = false;
    }
}
Run Code Online (Sandbox Code Playgroud)


任何帮助将非常感激.

firefox scroll angular

6
推荐指数
4
解决办法
3万
查看次数

标签 统计

angular ×1

firefox ×1

scroll ×1