当我尝试按百分比添加宽度时,它不起作用。它显示每行的图像。
有什么办法可以解决这个问题吗?
这是我的 HTML 代码:
<ngx-masonry [options]="options" [ordered]="true">
<div ngxMasonryItem class="masonry-item" *ngFor="let item of gallery" [style.width.%]="[item.width]">
<a class="" href="/assets/images/gallery/{{item.image}}" data-fancybox="gallery">
<img src="/assets/images/gallery/{{item.image}}" class="img-fluid" alt="">
</a>
</div>
</ngx-masonry>
TS代码:
public options: NgxMasonryOptions = {
itemSelector: '.masonry-item',
gutter: 10,
resize: true,
};
public gallery = [
{
'image' : 'image1.jpg',
'width' : '50%'
},
{
'image' : 'image2.jpg',
'width' : '25%'
},
{
'image' : 'image3.jpg',
'width' : '25%'
},
{
'image' : 'image4.jpg',
'width' : '50%'
},
{
'image' : 'image5.jpg',
'width' : '50%'
}
]
我已将代码更新为,
TS
public options: NgxMasonryOptions = {
itemSelector: '.masonry-item',
gutter: 0,
resize: true,
};
public gallery = [
{
'image' : 'https://images.unsplash.com/photo-1578133630261-a79a92922335?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=400&q=80&w=400',
'width' : 50,
},
{
'image' : 'https://images.unsplash.com/photo-1578133630261-a79a92922335?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=400&q=80&w=400',
'width' : 25,
},
{
'image' : 'https://images.unsplash.com/photo-1578133630261-a79a92922335?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=400&q=80&w=400',
'width' : 25,
},
{
'image' : 'https://images.unsplash.com/photo-1578133630261-a79a92922335?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=400&q=80&w=400',
'width' : 25,
},
{
'image' : 'https://images.unsplash.com/photo-1578133630261-a79a92922335?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=400&q=80&w=400',
'width' : 25,
},
{
'image' : 'https://images.unsplash.com/photo-1578133630261-a79a92922335?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=400&q=80&w=400',
'width' : 25,
},
{
'image' : 'https://images.unsplash.com/photo-1578133630261-a79a92922335?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=400&q=80&w=400',
'width' : 25,
},
]
HTML
<ngx-masonry [options]="options" [ordered]="true">
<div ngxMasonryItem class="masonry-item ratio ratio-1x1" *ngFor="let item of gallery" [style.width.%]="[item.width]">
<img src="{{ item.image }}" style="width: 100%;">
</div>
</ngx-masonry>
它不能正常工作.......................... ......................
谢谢。