开发中安卓机上遇到的软键盘弹出导致布局问题
在这里插入代码片
<div class="container">
<div class="appContainer" :style="{height:isKeyboardOpen? Heights :'inherit'}">
<p class="name">
<input
class="grow"
type="text"
v-model="name"
@focus="handleInputFocus"
@blur="handleInputBlur"
/>
</p>
</div>
<div :class="['footer', { 'keyboard-active': isKeyboardOpen }]">
<div class="next" @click="nextClick">下一步</div>
<div class="step next" @click="stepClick">上一步</div>
</div>
</div>
在这里插入代码片
data() {
return {
name:'',
isKeyboardOpen: false,
originalWindowHeight: window.innerHeight,
isAndroid: /Android/i.test(navigator.userAgent),
Heights:'inherit'
};
}
mounted() {
if(this.isAndroid) {
window.addEventListener("resize", this.handleWindowResize);
}
},
beforeDestroy() {
if (this.isAndroid) {
window.removeEventListener("resize", this.handleWindowResize);
}
},
methods: {
stepClick(){
console.log('上一步');
},
nextClick(){
if(!this.name){
Toast("请输入姓名");
return;
}
console.log('下一步');
},
handleInputFocus() {
if (this.isAndroid) {
this.handleWindowResize();
}
},
handleInputBlur() {
if (this.isAndroid) {
this.handleWindowResize();
}
},
handleWindowResize() {
if (this.isAndroid) {
const currentWindowHeight = window.innerHeight;
this.Heights=currentWindowHeight + 'px';
this.isKeyboardOpen = currentWindowHeight < this.originalWindowHeight;
}
}
}
<style>
.footer.keyboard-active {
position: relative;
bottom: 0;
}
</style>
