遍历图片数组,每个图片的背景色都是图片的主颜色
以下是uniapp 版本 仅有标签不同
<view
class="image-box"
:style="{
backgroundImage: `linear-gradient(to top, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0.8)), url(${item.imageUrl[0]})`
}"
>
<image :src="item.imageUrl ? item.imageUrl[0] : ''" ></image>
</view>
image-box 动态设置图片盒子的背景图片
:style="{
backgroundImage: `linear-gradient(to top, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0.8)), url(${item.imageUrl[0]})`
}"
注意这里用linear-gradient 是因为如果用opacity设置背景的透明度会影响到内部图片的展示
image-box css 中
background-position: 40% 50%;
background-size: 20000%;
设置背景位置,然后放大取色