[英]Ionic v4 ion-img eagerly loads the images instead of lazy-loading
I have a horizontal scroller that I built with FlexLayoutModule
that basically let's me have a horizontally scrollable list where every item is a column of image and text. 我有一个用
FlexLayoutModule
构建的水平滚动FlexLayoutModule
,基本上让我有了一个水平滚动的列表,其中每个项目都是一列图像和文本。 Here's the relevant code from my scroller.component.html
这是我的
scroller.component.html
的相关代码
<div class="ion-activatable container" fxLayout="column" fxLayoutAlign="start center" fxLayoutGap="10px" *ngFor="let item of items">
<ion-ripple-effect></ion-ripple-effect>
<div *ngIf="item.movie || item.title" [routerLink]="'/tabs/discover/movie/'+ (item.movie? item.movie.ids.tmdb: item.ids.tmdb)">
<ion-img class="poster" [src]="(images$[item.movie? item.movie.ids.tmdb: item.ids.tmdb] | async) || preloaderGif"></ion-img>
<div class="item-titles">
{{item.movie? item.movie.title: item.title}}
</div>
</div>
</div>
But when the page loads up, all the hundreds of image requests are fired which I can see from the network tab as well as my API reporting I have hundreds of pending requests and that I have hit rate-limiting. 但是,当页面加载完毕时,将触发所有数百个图像请求,这些图像请求可以从“网络”选项卡以及我的API报告中看到,我有数百个待处理的请求,并且达到了速率限制。 Maybe I'm not using the ion-img right or maybe some of the styles are messing with it?
也许我没有正确使用ion-img,或者某些样式弄乱了它? Here's my
scroller.component.scss
: 这是我的
scroller.component.scss
:
.horizontal {
white-space: nowrap;
overflow-x: auto;
}
.poster {
width: 92px;
height: 138px;
}
.container {
position: relative;
cursor: pointer;
user-select: none;
}
.item-titles {
width: 100px;
white-space: normal;
text-align: center;
}
I'm open to suggestions. 我愿意提出建议。 Maybe I should use
virtual-scroll
? 也许我应该使用
virtual-scroll
? But I don't see how I can make that horizontal. 但是我看不到如何使它水平。
I have done this kind of design using ion-slide
. 我已经使用
ion-slide
完成了这种设计。 Better to do some scss change to show the part of next element. 最好进行一些scss更改以显示下一个元素的一部分。 Please have a look following code.
请看下面的代码。
Html HTML
<ion-slides [options]="slideOpts" class="recent-search">
<ion-slide *ngFor="let item of recentSearch" class="slide-container" float-left text-left>
<div class="history-item" (click)="gotoDetailPage(item.id)">
<div class="container" float-left text-left>
<div class="bold-text">{{item.companyName}}</div>
<div>{{item.productName}}</div>
<div>{{item.descriptor}}</div>
</div>
</div>
</ion-slide>
</ion-slides>
Scss SCSS
.slide-container {
.history-item {
width: 100%;
padding: 3px;
.container {
padding: 15px;
background-color: #fafafa;
box-shadow: 2px 2px 11px 3px rgba(0, 0, 0, 0.12);
width: 80%;
font-size: 12px;
color: #767676;
.bold-text {
font-weight: 700;
}
div {
padding: 4px 0;
}
}
}
}
This is how it looks like. 这就是它的样子。
This works nice for me with huge list of data. 对于大量数据列表,这对我来说很好。 Hope this may help to someone else.
希望这对其他人有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.