angular2滚动然后固定标头在bootstrap整页模态问题

时间:2017-03-07 17:18:27

标签: css angular typescript ng2-bootstrap

尝试在ng2-bootstrap模式(整页)中创建scroll-then-fix div。我在这里看到两个问题: a)可以检测到'this.document.body.scrollTop'的值,但是无法检测到'this.el.nativeElement.offsetTop'。 b)sass类没有工作,因为div在bootstrap模式中。

HTML:在bootstrap模态体

<div[class.fixed]="navIsFixed" #fixedButtons> </div>      

打字稿:

 @ViewChild ('fixedButtons') el: ElementRef;
 @HostListener("window:scroll", [])
  onWindowScroll() {
    let number = this.el.nativeElement.offsetTop;
    if (number > 65) {
      this.navIsFixed = true;
    } else if (this.navIsFixed && number < 10) {
      this.navIsFixed = false;
    }
  }

SCSS:

.fixed {
  position:fixed;
  margin:0;
  top:0;
}

0 个答案:

没有答案