偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

總結(jié)幾個(gè)移動(dòng)端H5軟鍵盤的大坑

開發(fā) 前端
Element.scrollIntoViewIfNeeded()方法也是用來將不在瀏覽器窗口的可見區(qū)域內(nèi)的元素滾動(dòng)到瀏覽器窗口的可見區(qū)域。但如果該元素已經(jīng)在瀏覽器窗口的可見區(qū)域內(nèi),則不會(huì)發(fā)生滾動(dòng)。

1. 部分機(jī)型軟鍵盤彈起擋住原來的視圖

解決方法:可以通過監(jiān)聽移動(dòng)端軟鍵盤彈起。

Element.scrollIntoView() 方法讓當(dāng)前的元素滾動(dòng)到瀏覽器窗口的可視區(qū)域內(nèi)。參數(shù)如下:

  • true,表示元素的頂部與當(dāng)前區(qū)域的可見部分的頂部對(duì)齊
  • false,表示元素的底部與當(dāng)前區(qū)域的可見部分的尾部對(duì)齊

[[319677]]

Element.scrollIntoViewIfNeeded()方法也是用來將不在瀏覽器窗口的可見區(qū)域內(nèi)的元素滾動(dòng)到瀏覽器窗口的可見區(qū)域。但如果該元素已經(jīng)在瀏覽器窗口的可見區(qū)域內(nèi),則不會(huì)發(fā)生滾動(dòng)。此方法是標(biāo)準(zhǔn)的Element.scrollIntoView()方法的專有變體。

  1. window.addEventListener('resize', function() { 
  2.   if (document.activeElement.tagName === 'INPUT' || document.activeElement.tagName === 'TEXTAREA') { 
  3.     window.setTimeout(function() { 
  4.       if ('scrollIntoView' in document.activeElement) { 
  5.         document.activeElement.scrollIntoView(false) 
  6.       } else { 
  7.         document.activeElement.scrollIntoViewIfNeeded(false) 
  8.       } 
  9.     }, 0) 
  10.   } 
  11. }) 

2. ios 鍵盤收起時(shí)頁(yè)面沒有回落,底部會(huì)留白

部分蘋果手機(jī)填寫表單的時(shí)候的,輸入內(nèi)容后關(guān)閉軟鍵盤,底部會(huì)留一塊空白。這種情況可以通過監(jiān)聽鍵盤回落時(shí)間滾動(dòng)到原來的位置。

  1. window.addEventListener('focusout', function() { 
  2.   window.scrollTo(0, 0) 
  3. }) 
  4.  
  5. //input輸入框彈起軟鍵盤的解決方案。 
  6. var bfscrolltop = document.body.scrollTop 
  7. $('input') 
  8.   .focus(function() { 
  9.     documentdocument.body.scrollTop = document.body.scrollHeight 
  10.     //console.log(document.body.scrollTop); 
  11.   }) 
  12.   .blur(function() { 
  13.     document.body.scrollTop = bfscrolltop 
  14.     //console.log(document.body.scrollTop); 
  15.   }) 

3. onkeyUp 和 onKeydown 兼容性問題

部分 ios 機(jī)型 中 input 鍵盤事件 keyup、keydown、等支持不是很好, 用 input 監(jiān)聽鍵盤 keyup 事件,在安卓手機(jī)瀏覽器中沒有問題,但是在 ios 手機(jī)瀏覽器中用輸入法輸入之后,并未立刻相應(yīng) keyup 事件:

  • onkeypress 用戶按下并放開任何字母數(shù)字鍵時(shí)發(fā)生。系統(tǒng)按鈕(箭頭鍵和功能鍵)無法得到識(shí)別。
  • onkeyup 用戶放開任何先前按下的鍵盤鍵時(shí)發(fā)生。
  • onkeydown 用戶按下任何鍵盤鍵(包括系統(tǒng)按鈕,如箭頭鍵和功能鍵)時(shí)發(fā)生。

4. ios12 輸入框難以點(diǎn)擊獲取焦點(diǎn),彈不出軟鍵盤

定位找到問題是 fastclick.js 對(duì) ios12 的兼容性,可在 fastclick.js 源碼或者 main.js 做以下修改:

  1. FastClick.prototype.focus = function(targetElement) { 
  2.   var length 
  3.   if (deviceIsIOS && targetElement.setSelectionRange && targetElement.type.indexOf('date') !== 0 && targetElement.type !== 'time' && targetElement.type !== 'month') { 
  4.     length = targetElement.value.length 
  5.     targetElement.setSelectionRange(length, length) 
  6.     targetElement.focus() 
  7.   } else { 
  8.     targetElement.focus() 
  9.   } 

5. fastclick 導(dǎo)致下拉框焦點(diǎn)沖突

移動(dòng)端使用 fastclick 之后,在 ios 環(huán)境下,有幾個(gè)連續(xù)的下拉框 第一個(gè) select 框突然填充了第二個(gè)下拉框的內(nèi)容。

根本原因是 Fastclick 導(dǎo)致 ios 下多個(gè) select ,點(diǎn)擊某一個(gè),焦點(diǎn)不停變換的 bug。修改源碼,在 onTouchStart 事件內(nèi)判斷設(shè)備是否為 ios,再判斷當(dāng)前 nodeName 是否為 select,如果是 return false 去阻止 fastClick 執(zhí)行其他事件。

  1. //line 391行 
  2. FastClick.prototype.onTouchStart = function(event) { 
  3.   //在其方法中添加判斷 符合ios select的時(shí)候 不返回事件 
  4.   if (deviceIsIOS && this.targetElement == 'select') this.targetElement = null 
  5.   event.preventDefault() 
  6. //line521 或者講源碼中 有關(guān)touchEnd判斷非ios或者非select的事件注釋, 
  7. if (!deviceIsIOS || targetTagName !== 'select') { 
  8.   this.targetElement = null 
  9.   event.preventDefault() 

6. ios 下 fixed 失效的原因

軟鍵盤喚起后,頁(yè)面的 fixed 元素將失效,變成了 absolute,所以當(dāng)頁(yè)面超過一屏且滾動(dòng)時(shí),失效的 fixed 元素就會(huì)跟隨滾動(dòng)了。不僅限于 type=text 的輸入框,凡是軟鍵盤(比如時(shí)間日期選擇、select 選擇等等)被喚起,都會(huì)遇到同樣地問題。

解決方法: 不讓頁(yè)面滾動(dòng),而是讓主體部分自己滾動(dòng),主體部分高度設(shè)為 100%,overflow:scroll

  1. <body> 
  2.   <div class='warper'> 
  3.     <div class='main'></div> 
  4.   <div> 
  5.   <div class="fix-bottom"></div> 
  6. </body>
  1. .warper { 
  2.   position: absolute; 
  3.   width: 100%; 
  4.   left: 0; 
  5.   right: 0; 
  6.   top: 0; 
  7.   bottom: 0; 
  8.   overflow-y: scroll; 
  9.   -webkit-overflow-scrolling: touch; /* 解決ios滑動(dòng)不流暢問題 */ 
  10. .fix-bottom { 
  11.   position: fixed; 
  12.   bottom: 0; 
  13.   width: 100%; 

7. ios 鍵盤換行變?yōu)樗阉?/strong>

  • input type="search"
  • input 外面套 form,必須要有 action,action="javascript:return true"
  • 表單提交阻止默認(rèn)提交事件
  1. <form action="javascript:return true" @submit.prevent="formSubmit"> 
  2.   <input type="search" placeholder="請(qǐng)輸入訴求名稱" id="search" /> 
  3. </form> 

 

責(zé)任編輯:趙寧寧 來源: 前端先鋒隊(duì)
相關(guān)推薦

2019-04-25 10:20:22

H5軟鍵盤前端

2022-10-26 09:01:55

H5移動(dòng)端調(diào)試

2021-06-23 06:30:14

H5 移動(dòng)端前端開發(fā)

2009-08-21 13:25:49

C#打開軟鍵盤

2024-03-06 09:16:57

PAD設(shè)備kikaInput鴻蒙

2015-12-03 15:27:46

2021-08-07 15:31:45

Windows 10Windows微軟

2015-12-03 10:47:49

2015-12-16 12:40:32

H5緩存機(jī)制移動(dòng)

2024-04-11 10:02:06

iOS鍵盤Android

2024-05-06 08:28:09

Android窗口鍵盤

2017-12-05 15:26:19

2017-12-05 13:12:35

Android軟鍵盤參數(shù)

2015-07-15 12:30:37

移動(dòng)端H5高清多屏

2015-07-15 14:38:54

H5移動(dòng)適配

2013-06-27 17:26:01

AndroidEditText

2021-07-13 09:49:08

鴻蒙HarmonyOS應(yīng)用

2017-08-16 10:57:25

H5HTML開發(fā)

2021-04-27 07:52:19

C++promisefuture

2017-07-03 17:20:55

Android軟鍵盤控制開發(fā)問題
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)