提交 20ac8afe 编写于 作者: DCloud-yyl's avatar DCloud-yyl

兼容input框在软键盘高度变化时显示位置正确

上级 2c020568
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
</list-view> </list-view>
<web-view v-if="indexView==2" src="/hybrid/html/local.html" id="webv" class="scroll-view"></web-view> <web-view v-if="indexView==2" src="/hybrid/html/local.html" id="webv" class="scroll-view"></web-view>
<view style="position:relative;background-color:white;z-index:1000;" :style="{bottom: inputBottom}"> <view style="position:relative;background-color:white;z-index:1000;" :style="{bottom: inputBottom}">
<input placeholder="滚动视图外的居底输入框,不上推,手动控制输入框top" adjust-position="false" @blur="onInputBlur" @keyboardheightchange="onInputKeyboardChange" /> <input id="input" placeholder="滚动视图外的居底输入框,不上推,手动控制输入框top" adjust-position="false" @blur="onInputBlur" @keyboardheightchange="onInputKeyboardChange" />
</view> </view>
</view> </view>
...@@ -53,6 +53,7 @@ ...@@ -53,6 +53,7 @@
navigationBarTextColor: '#000', navigationBarTextColor: '#000',
indexView: 0, indexView: 0,
windowHeight: 0, windowHeight: 0,
inputRemainHeight: 0, //输入框距离底部的距离
inputBottom: '0px' inputBottom: '0px'
} }
}, },
...@@ -105,9 +106,7 @@ ...@@ -105,9 +106,7 @@
this.inputBottom = '0px'; this.inputBottom = '0px';
}, },
onInputKeyboardChange(e:UniInputKeyboardHeightChangeEvent) { onInputKeyboardChange(e:UniInputKeyboardHeightChangeEvent) {
let inputBottom = e.target?.getBoundingClientRect()?.bottom??this.windowHeight; let bottom = (this.inputRemainHeight > e.detail.height)?0:(e.detail.height-this.inputRemainHeight);
let remainHeight = this.windowHeight - inputBottom;
let bottom = (remainHeight > e.detail.height)?0:(e.detail.height-remainHeight);
this.inputBottom = `${bottom}px`; this.inputBottom = `${bottom}px`;
}, },
// 自动化测试 // 自动化测试
...@@ -120,10 +119,12 @@ ...@@ -120,10 +119,12 @@
}, },
}, },
onReady() { onReady() {
this.windowHeight = uni.getWindowInfo().windowHeight; let windowHeight = uni.getWindowInfo().windowHeight;
this.remainHeight = windowHeight - (uni.getElementById('input')?.getBoundingClientRect()?.bottom??windowHeight);
}, },
onResize() { onResize() {
this.windowHeight = uni.getWindowInfo().windowHeight; let windowHeight = uni.getWindowInfo().windowHeight;
this.remainHeight = windowHeight - (uni.getElementById('input')?.getBoundingClientRect()?.bottom??windowHeight);
} }
} }
</script> </script>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册