Commit 154e58b9 authored by JingChao's avatar JingChao

content

parent ab1f4ed9
...@@ -21,95 +21,15 @@ export default { ...@@ -21,95 +21,15 @@ export default {
}, },
data () { data () {
return { return {
docmHeight: 0, // 默认屏幕高度
showHeight: 0, // 实时屏幕高度
topHeight: 0, // content距离顶部的高度
contentsHeight: 0, // 内容区域本来高度
isResize: false, // 默认屏幕高度是否已获取
fontSize: Number(window.document.documentElement.style.fontSize.replace('px', '')), fontSize: Number(window.document.documentElement.style.fontSize.replace('px', '')),
winHeight: window.innerHeight, winHeight: window.innerHeight,
winWidth: window.innerWidth, winWidth: window.innerWidth,
contentScrollTop: 0,
} }
}, },
watch: {
'showHeight': function () {
if ($config.isMobilePlatform && detectOS() === 'android') {
if (this.docmHeight >= this.showHeight) {
// 软键盘弹出的事件处理
let activeElement = document.activeElement
let offsetTop = activeElement.offsetTop
let offsetParent = activeElement.offsetParent
let viewTop = offsetParent.clientHeight
this.topHeight = this.$el.offsetTop
if (activeElement === document.body) {
return
}
while (offsetParent !== document.body) {
offsetTop += offsetParent.offsetTop
offsetParent = offsetParent.offsetParent
}
offsetTop = this.docmHeight - offsetTop - viewTop < 0 ? offsetTop - this.topHeight - viewTop : 0
if (offsetTop > 0) {
this.$el.style.transition = 'all .2s cubic-bezier(0.165, 0.84, 0.44, 1) 0s'
this.$el.style.transform = 'translate(0px, -' + offsetTop + 'px) scale(1) translateZ(0px)'
this.$el.style.height = parseInt(this.contentsHeight) + offsetTop + 'px'
}
} else {
// 软键盘收起的事件处理
this.$el.style.height = parseInt(this.contentsHeight) + 'px'
this.$el.style.transform = 'translate(0px, 0px) scale(1) translateZ(0px)'
}
}
},
},
mounted () { mounted () {
if (this.calContent) { if (this.calContent) {
this.contentHeight() this.contentHeight()
} }
this.contentsHeight = this.$el.style.height.slice(0, this.$el.style.height.length - 2)
if ($config.isMobilePlatform && detectOS() === 'ios') {
document.body.addEventListener('focusin', () => {
// 软键盘弹出的事件处理
let keyboardHeight = this.getKeyBoardHeight()
let activeElement = document.activeElement
let offsetTop = activeElement.offsetTop
let offsetParent = activeElement.offsetParent
if (activeElement === document.body) {
return
}
while (offsetParent !== document.body) {
offsetTop += offsetParent.offsetTop
offsetParent = offsetParent.offsetParent
}
debugger
offsetTop = (innerHeight - offsetTop) < keyboardHeight ? (keyboardHeight - (innerHeight - offsetTop)) : 0
if (offsetTop > 0) {
this.$el.style.transition = 'all .2s cubic-bezier(0.165, 0.84, 0.44, 1) 0s'
this.$el.style.transform = 'translate(0px, -' + offsetTop + 'px) scale(1) translateZ(0px)'
this.$el.style.height = parseInt(this.contentsHeight) + offsetTop + 'px'
}
})
document.body.addEventListener('focusout', () => {
// 软键盘收起的事件处理
this.$el.style.height = parseInt(this.contentsHeight) + 'px'
this.$el.style.transform = 'translate(0px, 0px) scale(1) translateZ(0px)'
})
}
// 当视图窗口大小发生改变时
window.onresize = () => {
return (() => {
if (!this.isResize) {
// 默认屏幕高度
this.docmHeight = document.documentElement.clientHeight
this.isResize = true
}
// 实时屏幕高度
this.showHeight = document.body.clientHeight
})()
}
}, },
methods: { methods: {
getHeaderHeight () { getHeaderHeight () {
...@@ -168,19 +88,6 @@ export default { ...@@ -168,19 +88,6 @@ export default {
let content = vm.$el let content = vm.$el
content.style.height = (window.innerHeight - nextHeight - headerHeight) + 'px' content.style.height = (window.innerHeight - nextHeight - headerHeight) + 'px'
}, },
// 键盘的高度
getKeyBoardHeight () {
var innerWidth = window.innerWidth
if (detectOS() === 'ios') {
if (innerWidth >= 375 && innerHeight >= 812) {
return 460
}
return 400
} else {
return 300
}
},
}, },
} }
</script> </script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment