1. 当弹出键盘时,会改变页面高度,影响页面样式
通过window.onsize事件可以控制键盘弹出或消失的时候的样式
var h = document.body.scrollHeight // 用onresize事件监控窗口或框架被调整大小,先把一开始的高度记录下来 window.onresize = function () { // 如果当前窗口小于一开始记录的窗口高度,那就让当前窗口等于一开始窗口的高度 // alert("h:" + h + "; <br> height:" + document.body.scrollHeight) if (document.body.scrollHeight < h) { document.body.style.height = h + "px" } }
2. H5无法控制手机横屏的操作(安卓和ios可以),为了避免某些情况下横屏,解决方案如下
(function noTransformX(){ var orientation=window.orientation; var pd = null; function createPd(){ if(document.getElementById(‘preventTran‘) === null){ var imgData = ‘data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAABaCAYAAADkUTU1AAAI9ElEQVR4Xu1cfXBcVRU/5+Z1N8GEj2AhFQvUIigfBetYaRVbBhADU2wHVoYk3bx3k8kMcSyFPxzUf8IfOjrqIHYUXbL3vW6mKXbtINapg1ColLEUnYIj9QPGOE0VdUjjlE3tdnffO87J7GY26yZ9H5tNst37X5tzzu/87rl777v3nnMR5rhFo9HLhBDrhRC3AMBqAFgBABfmYU8CwAgAHAGAVwDgJaXUO+Vc6u7uXhkOh0/GYrGxIC5jEOVZdLG3t7fdcZyHiOgORHSL4xDRfiHEE/F4fB8AEGNIKdcS0fMA8IxpmluC+OzWEdcY0Wh0jaZp2wFgjWulMoJE9CoRbRVCEHcCIp4PAOOpVOqSZDJp+7VdMcIbNmzQVqxYMYCIXwEA4dehEj2O+GlEfF/h/xFxfTwef9mv/YoQ7u/vb06n00kA+FypIxweAHgdAJ4DgF9nMpmj4+Pj77Jca2vr0nA4fC0ArAeAO4lotYvh/22l1JfnjXAkEmluaWn5JQB8ukx09hLRgGVZb7hxUNf1m4QQjxHRxlmI/0kpxZ3kqwWNMEopfwIAkRL0fwNAn1Lq51696ujouKKxsfEwAFw6k246nV45PDzMs7vnFoiwlPIRAPhuCeqbjuPcYVnWv7x609nZ+cFwOMzL0xVn0d2qlOKJ0XPzTZj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7Ztr+WTRSJaW67eiSfBTCazeefOne+56bjZZAIRzhtmG8Q7mba2tu8AwBcrWKTFnfX4yMjIowcOHMgFJcv6lSA8zQ8p5a0AwJPZqiAOEtEb/AigZVkHg9gp1a04YQaIRCINzc3N9yHil4honYeIF4b/9/Pf374np5k6aU4IF4NJKT8EAO355E5+NelyACjcBvJ7WKMAwLusV3K53L5EIsH/nrP2PzAJNfmP9znfAAAAAElFTkSuQmCC‘; pd = document.createElement(‘div‘); pd.setAttribute(‘id‘,‘preventTran‘); pd.style.position = ‘fixed‘; pd.style.left = ‘0‘; pd.style.top = ‘0‘; pd.style.width = ‘100%‘; pd.style.height = ‘100%‘; pd.style.overflow = ‘hidden‘; pd.style.backgroundColor = ‘#2e2e2e‘; pd.style.textAlign = ‘center‘; pd.style.zIndex = ‘99999‘; document.getElementsByTagName(‘body‘)[0].appendChild(pd); var img = document.createElement(‘img‘); img.src = imgData; pd.appendChild(img); img.style.margin = ‘60px auto 30px‘ var br = document.createElement(‘br‘); var p = document.createElement(‘p‘); p.style.width = ‘100%‘; p.style.height = ‘auto‘; p.style.fontSize = ‘22px‘; p.style.color = ‘#626262‘; p.style.lineHeight = ‘34px‘; p.style.textAlign = ‘center‘; p.innerHTML = ‘为了您的良好体验‘; p.appendChild(br); p.innerHTML += ‘请将手机/平板竖屏操作‘; pd.appendChild(p); } } if(orientation==90||orientation==-90){ if(pd == null && document.getElementById(‘preventTran‘) === null) createPd(); document.getElementById(‘preventTran‘).style.display = ‘block‘; } window.onorientationchange=function(){ if(pd == null && document.getElementById(‘preventTran‘) == null) createPd(); document.getElementById(‘preventTran‘).style.display=‘none‘; noTransformX(); }; })();
参考自: https://www.cnblogs.com/hanguozhi/p/7405840.html
原文地址:https://www.cnblogs.com/zhuxingqing/p/12082888.html
时间: 2024-11-13 09:59:11