input ios键盘遮挡

直接放代码

 

// 获取焦点
focusInput() {
  let commentDom = document.querySelector('#textarea')
  setTimeout(function() {
    commentDom.scrollIntoView(true);
    commentDom.scrollIntoViewIfNeeded();
  }, 500)
},

在使用的input 或者textarea 需要被键盘顶起来,被顶起来的容器元素id为textarea

以上如果还不可以,在做第二步操作:给这个元素设置position:sticky

 

转载于:https://www.cnblogs.com/zyt-it/p/11418575.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当软键盘弹出时,可能会遮挡输入框,为了避免这种情况,可以通过以下几种方式解决: 1. 使用CSS样式 可以通过设置输入框的bottom值,将输入框向上移动,避免被软键盘遮挡。 ``` input { position: fixed; bottom: 0; } input:focus { bottom: 200px; } ``` 2. 使用JavaScript 可以通过监听软键盘的弹出和隐藏事件,根据软键盘的高度动态调整输入框的位置,避免被软键盘遮挡。 ``` var input = document.querySelector('input'); var keyboardHeight = 0; window.addEventListener('resize', function() { var currentKeyboardHeight = window.innerHeight - document.body.clientHeight; if (currentKeyboardHeight > 0 && currentKeyboardHeight !== keyboardHeight) { keyboardHeight = currentKeyboardHeight; input.style.bottom = keyboardHeight + 'px'; } else { input.style.bottom = '0'; } }); ``` 3. 使用第三方插件 可以使用第三方插件来解决输入框被软键盘遮挡的问题。例如,vue-soft-keyboard插件可以监听软键盘的弹出和隐藏事件,并且动态调整页面布局,使得输入框不被软键盘遮挡。 ``` <template> <div> <input ref="inputRef" type="text"> <soft-keyboard :input="inputRef" @show="onSoftKeyboardShow" @hide="onSoftKeyboardHide"></soft-keyboard> </div> </template> <script> import softKeyboard from 'vue-soft-keyboard' export default { components: { softKeyboard }, data () { return { inputRef: null } }, methods: { onSoftKeyboardShow (e) { // 获取键盘高度并调整输入框位置 const height = e.detail.height this.$refs.inputRef.style.bottom = `calc(100vh - ${height}px)` }, onSoftKeyboardHide () { // 隐藏键盘并恢复输入框位置 this.$refs.inputRef.style.bottom = 0 } } } </script> ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值