【发布时间】:2019-01-02 12:05:18
【问题描述】:
我正在尝试在包含 ngfor 列表的 div 中强制进行偏移滚动
我在作为overflow-y的div上试过这个:
@ViewChild('list') listRef: ElementRef;
然后点击我用一些日志尝试这个以确保它被调用
this.listRef.nativeElement.offsetTop = 500;
什么都没有发生,知道我怎么能做到这一点吗?
编辑:
HTML:
<div
#gridContainerId
class="gridContainer">
<a *ngFor="let item of images;">
<img src="{{getImage(item)}}"/>
</a>
</div>
css:
.gridContainer {
height: 90vh;
overflow-y: scroll;
}
组件:
@ViewChild('gridContainerId') ref: ElementRef;
this.store.pipe(
select(fromImages.getImages),
takeWhile(() => this.componentActive)
).subscribe(imagesItems => {
this.images = imagesItems;
updateScroll();
}
);
updateScroll(){
this.ref.nativeElement.scrollTop = this.ref.nativeElement.scrollHeight;
}
【问题讨论】:
标签: javascript html angular typescript ngfor