angular - Angular:如何根据元素大小用物品填充容器,然后在容器装满后停止?
问题描述
我正在写一个无限滚动(不能使用现成的,因为我展示的东西有时会嵌套在一个对象中。
目前,用足够的元素填充容器效果很好,我知道它会滚动,但这需要猜测并且不可扩展。
我尝试使用我编写的相同代码来检测滚动大小并在显示数组的底部添加更多元素(在滚动上效果很好),但它只是填充所有内容而不是停止。我认为这是因为它没有在添加到显示数组的算法迭代之间重绘?有没有办法强制重绘,所以它会知道元素有多大?或者这在计算上是否会令人望而却步?
一些组件(现在是扁平的;对象嵌套稍后出现):
ngAfterViewInit(){
this.initted = true;
this.fillWithItems();
}
fillWithItems(){
if(this.initted){
while(this.icons.length && this.needMore(this.iconContainerRef.nativeElement)){
this.displayIcons.push(...this.icons.splice(0,5));
}
}
}
onScroll(event: Event){
let scrollement = event.target as HTMLElement;
if(this.needMore(scrollement)) this.fillWithItems()
}
needMore(el){
return el.scrollHeight - el.scrollTop < 2 * el.clientHeight
}
解决方案
推荐阅读
- java - Hibernate./JPA 本机批量插入与重复键更新问题
- excel - 谷歌工作表宏粘贴从 Excel 工作表中复制的内容
- ruby-on-rails - Vue-meta 标签不更新使用 rails 作为后端的 meta 标签
- r - 无法在 R 中加载 avro 包
- cassandra - Cassandra 4.0 中缺少 CounterMutationStage 和 ViewMutationStage 指标
- flutter - 我正在寻找一个关于Package Compatibility的简单方法:所以,因为flutterapp同时依赖〇〇和〇〇版本解决失败
- java - Java - 等于和哈希码比较
- php - SendGrid API 使用 php ext-curl 发送多封电子邮件
- java - Eclipse UI 使用 Hibernate 配置抛出 NPE
- angular - 由于不允许的 MIME 类型(“application/json”),加载模块被阻止