关于页面input导致页面可滑动问题(iOS上)

本文介绍了解决iOS设备上页面滑动时输入框保持焦点的问题。通过监听滚动事件并移除输入框焦点,确保页面滚动流畅。适用于多个输入框场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

关于页面input导致页面可滑动问题(iOS上)

安卓关于弹出键盘问题可以用resize解决
解决方案:滑动页面的时候让对应的input失去焦点(默认滚动不失去焦点)

1.给input组件添加获取焦点事件,并传人对应input的参数

@onFocus="onFocus(0)"  //input绑定获取焦点事件

2.追加事件

onFocus(val){  //获取焦点事件
this.isScroll=true
   setTimeout(()=>{
            if(this.isScroll){
              this.inputName=val
              window.addEventListener('scroll', this.scrollEvent);
            }
          },800)
 }, 
  scrollEvent(){  //滚动事件
   var input1 =document.getElementsByClassName('inputState')[this.inputName]
   input1.blur()
   window.removeEventListener('scroll', this.scrollEvent);
 },
 getBlure(){  //失去焦点事件(过快失去焦点的时候不去绑定事件)
          this.isScroll=false
      },

如果页面有多个input,需要在input失去焦点或者其判断事件触发后移除滚动事件

3.销毁

   destroyed() {    //清除scroll事件
      window.removeEventListener('scroll', this.scrollEvent);
    },

转载于:https://www.cnblogs.com/liuhuanwen/p/8818767.html

要实现在iOS上文本框的上下滑动,可以通过以下方法实现。首先,您需要添加一个监听事件,当文本框获取焦点时,禁止默认的上下滑动效果。您可以使用以下代码来实现这一点: ```html <input type="text" id="queryTitle" value="$queryTitle" placeholder="主题" onfocus="input()" onblur="noInput()"> <script> function input() { document.body.addEventListener('touchmove', function(e) { e.preventDefault(); // 阻止默认的处理方式(阻止上下滑动的效果) }, { passive: false }); }; </script> ``` 然后,在文本框失去焦点时,您需要清除掉禁止滚动的监听事件,以实现文本框的上下滑动。可以使用以下代码来实现这一点: ```html <input type="text" id="queryTitle" value="$queryTitle" placeholder="主题" onfocus="input()" onblur="noInput()"> <script> function noInput() { document.body.removeEventListener('touchmove', function(e) { e.preventDefault(); }, { passive: false }); }; </script> ``` 需要注意的是,passive参数不能省略,它用来兼容iOS和Android。如果不写passive: false,iOS手机端将无法实现文本框的上下滑动。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [ios手机端数字显示黑色和input输入时禁止滑动的解决方案](https://blog.youkuaiyun.com/m0_65638748/article/details/126431292)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值