跳到主要内容
版本:3.x

CoverImage

覆盖在原生组件之上的图片视图。可覆盖的原生组件同cover-view,支持嵌套在cover-view里。

支持情况:

参考文档

类型

ComponentType<CoverImageProps>

示例代码

// js
class App extends Components {
render () {
return (
<View className='container'>
<Video id='myVideo' src='src'>
<CoverView className='controls'>
<CoverView className='play' onClick='play'>
<CoverImage className='img' src='src' />
</CoverView>
</CoverView>
</Video>
)
}
}
// css
.container {
position: relative;
}
.controls {
position: absolute;
top: 50%;
left: 50%;
width: 300px;
height: 225px;
transform: translate(-50%, -50%);
}

CoverImageProps

参数类型必填说明
srcstring图标路径,支持临时路径、网络地址、云文件ID。暂不支持base64格式。
referrerPolicy"origin" or "no-referrer"格式固定为 https://servicewechat.com/{appid}/{version}/page-frame.html,其中 {appid} 为小程序的 appid,{version} 为小程序的版本号,版本号为 0 表示为开发版、体验版以及审核版本,版本号为 devtools 表示为开发者工具,其余为正式版本;
fixedTopstring设置与容器顶部的固定距离,效果相当于在 CSS 中设置 position: fixed 和 top 值,该属性优先级高于 fixed-bottom,CSS 设置的 position、top、bottom 值
fixedRightstring设置与容器右侧的固定距离,效果相当于在 CSS 中设置 position: fixed 和 right 值,该属性优先级高于 CSS 设置的 position、left、right 值
fixedBottomstring设置与容器底部的固定距离,效果相当于在 CSS 中设置 position: fixed 和 bottom 值,该属性优先级高于 CSS 设置的 position、top、bottom 值
fixedLeftstring设置与容器左侧的固定距离,效果相当于在 CSS 中设置 position: fixed 和 left 值,该属性优先级高于 fixed-right,CSS 设置的 position、left、right 值
ariaRolestring无障碍访问,(角色)标识元素的作用
ariaLabelstring无障碍访问,(属性)元素的额外描述
onLoadCommonEventFunction图片加载成功时触发
onErrorCommonEventFunction图片加载失败时触发
onTapCommonEventFunction点击事件回调。

API 支持度

API微信小程序百度小程序支付宝小程序QQ 小程序京东小程序H5React NativeHarmony
CoverImageProps.src✔️✔️✔️✔️✔️✔️
CoverImageProps.referrerPolicy✔️
CoverImageProps.fixedTop✔️
CoverImageProps.fixedRight✔️
CoverImageProps.fixedBottom✔️
CoverImageProps.fixedLeft✔️
CoverImageProps.ariaRole✔️
CoverImageProps.ariaLabel✔️
CoverImageProps.onLoad✔️✔️✔️✔️✔️
CoverImageProps.onError✔️✔️✔️✔️✔️
CoverImageProps.onTap✔️