angular2+实现google photos效果

本文介绍了一种使用Angular实现图片响应式布局的方法。通过后台获取图片数据并动态调整每张图片的宽度、高度及填充比例,使图片能够适应不同屏幕尺寸,提升用户体验。布局采用Flexbox实现,并结合Angular的*ngFor指令进行图片列表的动态渲染。

ts: 

this.service.postData('/site_cnt/get_pictures', data).subscribe({
next: res => {
this.imgList = res.result.data;
for (const img of this.imgList) {
img['flexGrow'] = img.info.width * 200 / img.info.height;
img['width'] = img['flexGrow'] + 'px';
img['bottom'] = img.info.height / img.info.width * 100 + '%';
}
this.pageInfo = res.result.pageinfo;
}
});

html: 

<section class="img_section">
<div class="img_div" *ngFor="let img of imgList" [ngStyle]="{'width': img.width,'flex-grow': img.flexGrow}" (click)="handlePreview(img.url, img.title)">
<i class="img_i" [ngStyle]="{'padding-bottom': img.bottom}"></i>
<img class="img_img" src="{{siteinfo.ucs + img.url}}" [title]="img.title">
</div>
</section>

css: 

.img_section {
display: flex;
flex-wrap: wrap;
}
.img_section::after {
content: '';
flex-grow: 999999999;
}
.img_div {
margin: 2px;
background-color: violet;
position: relative;
cursor: pointer;
}
.img_i{
display: block;
}
.img_img {
position: absolute;
top: 0;
width: 100%;
vertical-align: bottom;
}



                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值