我做了一个博客网站,“高仿朋友圈”。 9 宫格的方法是先将 9 个 img 排 3 排,用原生 JS 获取单张照片的宽度,然后再把高度设置为宽度一样,这样就得到正方形效果了。 我这有个 iPhone 14 pro 看正常,安卓也正常,有个朋友用的 iPhone 13 ,说图片被拉成长柱子了,手边没有 13 的机器,咋测试呢?
图片样式代码是这样,兼容性有问题吗?
/* 5 张以上图片 */
.grid-pics img:nth-child(1):nth-last-child(n + 5),
.grid-pics img:nth-child(1):nth-last-child(n + 5)~img {
width: 32%;
margin-bottom: 1%;
}
var lstPicItem = document.querySelectorAll("#article .pic-item");
if (lstPicItem.length > 0) {
lstPicItem.forEach(x => {
x.style.height = lstPicItem[0].width + 'px';
})
}
