VH 两端不一致
safira 浏览器中 vh 包括工具栏,因此使用 vh 做布局时,在 safira 和非 safira 不一致,和使用 100%代替 vh,或者手动获取 innerHeight 设置高度,ios innerHeight 在弹下键盘不恢复,需提前记录
setElementHeight() { if (!this.innerHeight) this.innerHeight = window.innerHeight let height = this.innerHeight if (!this.isiOS) height = window.innerHeight const myElement = document.querySelector('.aigc-box') const pageBox = document.querySelector('.p-aigc-chat')
let myElementH = 0, pageH = height
if (!this.inputFocus) { myElementH = height - 68 - 155 } else { myElementH = height - 155 if (this.isiOS) myElementH = height - 155 - 30 }
myElement.style.height = myElementH + 'px' pageBox.style.height = pageH + 'px' },
|
resize 事件
弹起软键盘时,ios 会将整个 webview 向上推,且不触发 resize 事件,fixed 定位失效,在弹起键盘事件中获取 scollTop 做优化。
H5 键盘监控弹出(KeyboardUp)、收起(KeyboardDown)事件定义–兼容 Android、Ios
(function (window) { if (!window || !navigator) return; var u = navigator.userAgent; var isAndroid = u.indexOf("Android") > -1 || u.indexOf("Adr") > -1; var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
var KeyboardUpEvent = new Event("KeyboardUp", { bubbles: true, cancelable: true, });
var KeyboardDownEvent = new Event("KeyboardDown", { bubbles: true, cancelable: true, });
if (isAndroid) { var originalHeight = document.documentElement.clientHeight || document.body.clientHeight; window.onresize = function () { var resizeHeight = document.documentElement.clientHeight || document.body.clientHeight; if (resizeHeight - 0 < originalHeight - 0) { document.dispatchEvent(KeyboardUpEvent); } else { document.dispatchEvent(KeyboardDownEvent); } }; } else if (isiOS) { document.body.addEventListener("focusin", () => { document.dispatchEvent(KeyboardUpEvent); }); document.body.addEventListener("focusout", () => { document.dispatchEvent(KeyboardDownEvent); }); } else { console.log( "无法识别浏览器机型,请检查navigator.userAgent是否被重新定义过." ); } })(window);
|