代码示例:
1、创建dom并绑定click事件
btnBack = new plus.nativeObj.View('btnBack', {
top: systemInfo.statusBarHeight + 'px', // 此处top和left是相对于手机屏幕左上角为基准,不支持right
left: '10px',
height: '44px',
width: '24px'
})
btnBack.draw([
{
tag: 'img',
id: 'imgback',
src: '/static/icons/icon-back.png',
position: {
top: '10px', // 此处top和left相对于btnBack按钮左上角为基准
left: '0',
width: '24px',
height: '24px'
}
}
])
btnBack.addEventListener('click', () => {
const pages = getCurrentPages()
if (pages.length > 1) {
uni.navigateBack()
} else {
uni.switchTab({
url: '/pages/index/index'
})
}
})
2、显示与隐藏
btnBack.show() // 显示
btnBack.hide() // 隐藏
标签:app,pages,html5,btnBack,uni,top,24px,left
From: https://blog.51cto.com/u_16225519/7078769