做移动端项目,如何在键盘弹起时候,把聊天的消息顶到键盘的上方

给搜索框绑定获取焦点的事件
<u-input ref="input" v-model="value" type="text" :clearable='false' :height='80' @focus="handleFocus" />
			// 获取焦点,先判断是不是pc端,不是pc端才进行
// 关键代码
盒子的高度减去屏幕的高度,加上顶部导航栏的高度加上键盘的高度加上输入框的高度
			handleFocus() {
				var system = {};
				system.pingtai = /(Win32|Win16|WinCE|Mac68K|MacIntel|MacIntel|MacPPC|Linux mips64)/i.test(navigator.platform);
				if (system.pingtai) {
					//电脑
					return
				} else {

					// 获取聊天盒子的高度
					this.divHeight = document.getElementById('scrollview').getBoundingClientRect().height
					// 获取屏幕的高度
					this.originalHeight = document.documentElement.clientHeight || document.body.clientHeight;
					// 获取导航栏的高度
					this.healder = document.getElementById('healder').getBoundingClientRect().height
					// 获取输入框的高度
					this.submitHeight = document.getElementById('dialogueSubmit').getBoundingClientRect().height


					const that = this
					window.onresize = function() {
						// 获取可视区域的高度
						that.resizeHeight = document.documentElement.clientHeight || document.body.clientHeight;
						that.he = that.originalHeight + that.submitHeight - that.resizeHeight
						// 获取键盘
						that.keyboard = that.originalHeight - that.resizeHeight
						// alert(that.divHeight)
						if (that.divHeight >= that.resizeHeight - that.submitHeight - that.healder) {
							// alert("走没走")
							// alert(that.resizeHeight)
							const a = that.resizeHeight - that.healder - that.submitHeight
							that.yi = that.divHeight - a
							// alert(that.yi)

						}
						if (that.keyboard) {
							that.$nextTick(function() {
								setTimeout(() => {
									uni.pageScrollTo({
										scrollTop: that.divHeight - that.originalHeight + that.keyboard + that.submitHeight +
											this.healder,
										duration: 0
									})
								}, 0)
							})
						}



					}




				}

				// alert(this.divHeight)
			},

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值