docs(): add more docs about virtual-scroll and ion-img

This commit is contained in:
mhartington
2018-05-24 13:23:39 -04:00
parent 791353ccba
commit 373a97283f
4 changed files with 79 additions and 95 deletions

View File

@ -17,7 +17,7 @@ The `virtualScroll` and `*virtualItem` properties can be added to any element.
```html
<ion-list [virtualScroll]="items">
<ion-item *virtualItem="let item">
{% raw %}{{ item }}{% endraw %}
{{ item }}
</ion-item>
</ion-list>
```

View File

@ -0,0 +1,66 @@
```html
<ion-content>
<ion-virtual-scroll [items]="items" approxItemHeight="320px">
<ion-card *virtualItem="let item; let itemBounds = bounds;">
<div>
<img [src]="item.imgSrc" [height]="item.imgHeight" [alt]="item.name">
</div>
<ion-card-header>
<ion-card-title>{{ item.name }}</ion-card-title>
</ion-card-header>
<ion-card-content>{{ item.content }}</ion-card-content>
</ion-card>
</ion-virtual-scroll>
</ion-content>
```
```typescript
export class VirtualScrollPageComponent {
items: any[] = [];
constructor() {
for (let i = 0; i < 1000; i++) {
this.items.push({
name: i + ' - ' + images[rotateImg],
imgSrc: getImgSrc(),
avatarSrc: getImgSrc(),
imgHeight: Math.floor(Math.random() * 50 + 150),
content: lorem.substring(0, Math.random() * (lorem.length - 100) + 100)
});
rotateImg++;
if (rotateImg === images.length) {
rotateImg = 0;
}
}
}
}
const lorem = `Lorem ipsum dolor sit amet, consectetur adipiscing elit, seddo eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.`;
const images = [
'bandit',
'batmobile',
'blues-brothers',
'bueller',
'delorean',
'eleanor',
'general-lee',
'ghostbusters',
'knight-rider',
'mirth-mobile'
];
function getImgSrc() {
const src = `https://dummyimage.com/600x400/${Math.round(
Math.random() * 99999
)}/fff.png`;
rotateImg++;
if (rotateImg === images.length) {
rotateImg = 0;
}
return src;
}
let rotateImg = 0;
```