实现效果:图片右上角有个删除的小按钮
主要是父元素用相对定位,子元素用绝对定位。然后子元素通过left,top去调整位置。父类用相对定位 相对于原来的位置,所以不动。
微信小程序代码:
<view class="photo-preview" style="height:360rpx;">
<view wx:for="{{formData.selectedPhotos}}" wx:key="{{index}}" style="height:185rpx;width:185rpx;position: relative;">
<image src="{{item}}" mode="aspectFill" data-index="{{index}}">
</image>
<view class="delimg" style="position:absolute;top:0rpx;right:24rpx;width:15px;height:15px;background-color:red;line-height:15px;align-items:center;border-radius: 13%;" bindtap="removePhoto" data-index="{{index}}">×</view>
</view>
</view>