這個BUG 主要是固定在 ios里面不生效導致的,只要鍵盤彈起 就會把整個界面給彈上去,嘗試了網上各種辦法都沒有很好地解決
后來自己用代碼把固定定位的元素給拽下來的 原理就是監聽滾動 把固定的元素手動抓下來
看代碼
var u = navigator.userAgent; var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios終端 if (isIOS) { document.body.addEventListener('focusin', () => {// 軟鍵盤彈起事件 window.onscroll = function (e) { clearTimeout(that.time2) let scrollTop = document.documentElement.scrollTop || document.body.scrollTop; document.querySelector('.djq-editor-header').style.top = scrollTop + 'px'; document.querySelector('.djq-editor-header').style.display = 'none'; document.querySelector('.djq-editor-container').style.height = '300' + 'px'; that.time2 = setTimeout(() => {// 這邊是 判斷鍵盤彈起的狀態下 滾動結束后的狀態 let t2 = document.documentElement.scrollTop || document.body.scrollTop; that.setState({t2}); if (t2 == scrollTop) { document.querySelector('.djq-editor-header').style.display = 'flex'; } }, 180); } }) document.body.addEventListener('focusout', () => {// window.onscroll = null; window.scrollTo({ top: 0, left: 0, behavior: 'smooth' }); document.querySelector('.djq-editor-header').style.top = 0 + 'px'; document.querySelector('.djq-editor-header').style.display = 'flex'; document.querySelector('.djq-editor-container').style.height = '600px'; clearTimeout(that.time2) }) }
原理是就是 鍵盤彈起時 監聽頁面的滾動 把彈上去的元素給拽下來,因為是實時監聽,所以會有閃爍,這個時候我再滾動時候把他給隱藏了
然后再滾動結束的時候,再把他顯示出來,這個時候就要寫一個監聽合適滾動結束的函數。。。代碼就在上面 原理是 在滾動之后某個時間段
用定時器去判斷最后的scrolltop是否與實時滾動的scrolltop是否一致。。這個辦法親測有效。。有疑惑找我。。
但是最后 需求還是被砍了