其他分享
首页 > 其他分享> > ionic3 angular5 动态固定元素在屏幕位置

ionic3 angular5 动态固定元素在屏幕位置

作者:互联网

//ts 
import {Component, NgZone} from '@angular/core';
import {Content} from 'ionic-angular';
@ViewChild(Content) content: Content;
constructor(public zone: NgZone) {}
ionViewDidLoad(){
this.scrollListener();//调用监听方法
}

/**
* 开启滚动监听
*/
scrollListener() {
this.content.ionScroll.subscribe(($event: any) => {
this.zone.run(()=>{
if($event.scrollTop > 300) {
this.fixedShow = true;
}else {
this.fixedShow = false;
}
});
});
}


要固定的html放在ion-content外面。
//zone官方解释
滚动事件发生在Angular的区域之外。这是出于性能原因。因此,如果试图将值绑定到任何滚动事件,则需要将其包装在zone.run()中;

 
 

标签:content,滚动,zone,ionic3,Content,NgZone,angular5,屏幕,event
来源: https://www.cnblogs.com/wei-dong/p/11827466.html