相关疑难解决方法(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万
查看次数

角度2改变位置固定在滚动上

我有一个左侧边栏,位置固定.我想要实现的是,当我滚动大约50或60像素时,左侧边栏的位置应该更改为固定.

左sidebar.component.ts

import { Component } from '@angular/core';

@Component({
  moduleId: module.id,
  selector: 'left-sidebar',
  templateUrl: 'left-sidebar.html',
  styleUrls: ['left-sidebar.scss']
})
export class LeftSideBarComponent {
}
Run Code Online (Sandbox Code Playgroud)

左sidebar.html

<div class="col-sm-2 left-nav">

</div>
Run Code Online (Sandbox Code Playgroud)

CSS

.left-nav {
  position: absolute;
  background: #424242;
  height: 100%;
  overflow: auto;
  padding: 0;
  z-index: 1;
}
Run Code Online (Sandbox Code Playgroud)

如何在滚动条上将左侧边栏的位置从绝对位置更改为固定位置?

css angular2-template angular

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

标签 统计

angular ×2

angular2-template ×1

css ×1

firefox ×1

scroll ×1