在页面加载上,它应该向下滚动到一个特定的div --我使用下面的函数,但是问题是在页面加载之后,它在上下滚动时给了我问题,下面的函数不允许我正确地上下滚动。
ngAfterViewChecked(): void{
if (this.primary){
setTimeout(() => {
this.scrollTo.nativeElement.scrollIntoView();
},100);
}
}我没有使用超时,所以滚动没有从div位置移动。在那里修好了。但是一旦我使用了setTimeout,它就开始移动,但仍然给我带来了问题。我只想在页面加载时使用scrollIntoView。
发布于 2018-12-04 13:38:07
使用变量防止函数多次被调用。
isStarting:boolean=true;
ngAfterViewChecked(): void{
if (this.primary && this.isStarting){
setTimeout(() => {
this.scrollTo.nativeElement.scrollIntoView();
this.isStarting=false;
},100);
}
}https://stackoverflow.com/questions/53613935
复制相似问题