這是一個Firefox錯誤還是我搞砸了?如果我在真實設備(例如 Android)上使用 chrome 甚至 Firefox,沒有問題,它似乎只影響 Firefox 的響應式設計模式。這是復制問題所需的完整代碼:<html><head><meta charset="UTF-8"><meta name="viewport" id="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/></head><body><script>var pageInPortraintMode;// Prevent keyboard from squeezing the entire UIaddEventListener("load", function() { pageInPortraintMode = window.innerHeight > window.innerWidth; document.getElementById("viewport").setAttribute("content", "width=" + window.innerWidth + ", height=" + window.innerHeight + ", initial-scale=1.0, maximum-scale=1.0, user-scalable=0");})// Listen to window resizes to detect orientation changeswindow.addEventListener("resize", windowSizeChanged);function windowSizeChanged() { alert(window.innerWidth + "x" + window.innerHeight); if (((pageInPortraintMode === true) && (window.innerHeight < window.innerWidth)) || ((pageInPortraintMode === false) && (window.innerHeight > window.innerWidth))) { pageInPortraintMode = window.innerHeight > window.innerWidth; document.getElementById("viewport").setAttribute("content", "width=" + window.innerWidth + ", height=" + window.innerHeight + ", initial-scale=1.0, maximum-scale=1.0, user-scalable=0"); }}</script><div style="width:100%; height:100%; background-color:#000; position:fixed; left:0; top:0"></div></body></html>要復制進入響應式設計模式 (Ctrl+Shift+M),請加載 html,然后按“旋轉視口”按鈕。
響應式設計模式在屏幕旋轉后沒有為 window.innerWidth 返回正確的值
開心每一天1111
2022-10-27 15:42:29
