May 18, 2021 WeChat Mini Program Development Document
Image.
The property name | Type | The default | Description |
---|---|---|---|
Src | String | Picture resource address | |
mode | String | 'scaleToFill' | The mode in which the picture is cropped and scaled |
binderror | HandleEvent | When an error occurs, the event name posted to AppService, event object event.detail, serrMsg: 'something' wrong | |
bindload | HandleEvent |
When the picture is loaded, the event name posted to appService, the event object event.detail s
high: 'picture height px', width: 'picture width px'
} |
Note: Image components have a default width of 300px and a height of 225px
Mode valid value:
Mode has 13 modes, four of which are zoom modes and nine of which are crop modes.
Mode | Value | Description |
---|---|---|
Scaling | scaleToFill | The aspect ratio is not maintained to scale the picture so that the width of the picture is fully stretched to fill the image element |
Scaling | aspectFit | Keep the aspect ratio zooming the picture so that the long edges of the picture are fully displayed. That is, the picture can be displayed in its entirety. |
Scaling | aspectFill | Keep the aspect ratio zooming the picture, only to ensure that the short edges of the picture can be fully displayed. That is, the picture is usually complete only horizontally or vertically, and intercepts will occur in the other direction. |
Scaling | widthFix | The width remains the same, the height changes automatically, and the aspect ratio of the original figure remains unchanged |
Cutting | top | Do not zoom the picture, only the top area of the picture is displayed |
Cutting | bottom | Do not zoom the picture, only the bottom area of the picture is displayed |
Cutting | center | Do not zoom the picture, only the middle area of the picture is displayed |
Cutting | left | Do not zoom the picture, only the left area of the picture is displayed |
Cutting | right | Do not zoom the picture, only the right area of the picture is displayed |
Cutting | top left | Do not zoom the picture, only the upper left area of the picture is displayed |
Cutting | top right | Do not zoom the picture, only the upper right area of the picture is displayed |
Cutting | bottom left | Do not zoom the picture, only the lower left area of the picture is displayed |
Cutting | bottom right | Do not zoom the picture, only the lower right area of the picture is displayed |
Example:
<view class="page">
<view class="page__hd">
<text class="page__title">image</text>
<text class="page__desc">图片</text>
</view>
<view class="page__bd">
<view class="section section_gap" wx:for="{{array}}" wx:for-item="item">
<view class="section__title">{{item.text}}</view>
<view class="section__ctn">
<image style="width: 200px; height: 200px; background-color: #eeeeee;" mode="{{item.mode}}" src="{{src}}"></image>
</view>
</view>
</view>
</view>
Page({
data: {
array: [{
mode: 'scaleToFill',
text: 'scaleToFill:不保持纵横比缩放图片,使图片完全适应'
}, {
mode: 'aspectFit',
text: 'aspectFit:保持纵横比缩放图片,使图片的长边能完全显示出来'
}, {
mode: 'aspectFill',
text: 'aspectFill:保持纵横比缩放图片,只保证图片的短边能完全显示出来'
}, {
mode: 'top',
text: 'top:不缩放图片,只显示图片的顶部区域'
}, {
mode: 'bottom',
text: 'bottom:不缩放图片,只显示图片的底部区域'
}, {
mode: 'center',
text: 'center:不缩放图片,只显示图片的中间区域'
}, {
mode: 'left',
text: 'left:不缩放图片,只显示图片的左边区域'
}, {
mode: 'right',
text: 'right:不缩放图片,只显示图片的右边边区域'
}, {
mode: 'top left',
text: 'top left:不缩放图片,只显示图片的左上边区域'
}, {
mode: 'top right',
text: 'top right:不缩放图片,只显示图片的右上边区域'
}, {
mode: 'bottom left',
text: 'bottom left:不缩放图片,只显示图片的左下边区域'
}, {
mode: 'bottom right',
text: 'bottom right:不缩放图片,只显示图片的右下边区域'
}],
src: '../../resources/cat.jpg'
},
imageError: function(e) {
console.log('image3发生error事件,携带值为', e.detail.errMsg)
}
})
Original
scaleToFill
Do not maintain the aspect ratio to zoom the picture, so that the picture fully adapts
aspectFit
Keep the aspect ratio zooming the picture so that the long edges of the picture are fully displayed
aspectFill
Keep the aspect ratio zooming the picture, only to ensure that the short edges of the picture can be fully displayed
top
Do not zoom the picture, only the top area of the picture is displayed
bottom
Do not zoom the picture, only the bottom area of the picture is displayed
center
Do not zoom the picture, only the middle area of the picture is displayed
left
Do not zoom the picture, only the left area of the picture is displayed
right
Do not zoom the picture, only the area to the right of the picture is displayed
top left
Do not zoom the picture, only the upper left area of the picture is displayed
top right
Do not zoom the picture, only the upper right area of the picture is displayed
bottom left
Do not zoom the picture, only the lower left area of the picture is displayed
bottom right
Do not zoom the picture, only the lower right area of the picture is displayed