提交 52dda55d 编写于 作者: Q qiang

fix: app-v3 原生组件支持 fixed 定位

上级 0a677951
const TITLEBAR_HEIGHT = 44
function getStatusbarHeight () {
// 横屏时 iOS 获取的状态栏高度错误,进行纠正
return plus.navigator.isImmersedStatusbar() ? Math.round(plus.os.name === 'iOS' ? plus.navigator.getSafeAreaInsets().top : plus.navigator.getStatusbarHeight()) : 0
}
function getNavigationBarHeight () {
const webview = plus.webview.currentWebview()
let style = webview.getStyle()
style = style && style.titleNView
if (style && style.type === 'default') {
return TITLEBAR_HEIGHT + getStatusbarHeight()
}
return 0
}
function getFixed ($el) {
let fixed
while ($el) {
const style = getComputedStyle($el)
const transform = style.transform || style.webkitTransform
fixed = transform && transform !== 'none' ? false : fixed
fixed = style.position === 'fixed' ? true : fixed
$el = $el.parentElement
}
return fixed
}
export default {
name: 'Native',
data () {
......@@ -28,10 +57,13 @@ export default {
const rect = (this.$refs.container || this.$el).getBoundingClientRect()
this.hidden = rect.width === 0 || rect.height === 0
if (!this.hidden) {
['top', 'left', 'width', 'height'].forEach(key => {
const position = this.position
position.position = getFixed(this.$el) ? 'absolute' : 'static'
const keys = ['top', 'left', 'width', 'height']
keys.forEach(key => {
let val = rect[key]
val = key === 'top' ? val + (document.documentElement.scrollTop || document.body.scrollTop || 0) : val
this.position[key] = val + 'px'
val = key === 'top' ? val + (position.position === 'static' ? (document.documentElement.scrollTop || document.body.scrollTop || 0) : getNavigationBarHeight()) : val
position[key] = val + 'px'
})
}
},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册