這讓我發瘋。很多時候我都有傳送帶,而且我需要用JavaScript響應地重置屏幕高度。問題在於,對於移動設備,屏幕高度包括頂部的小URL窗口,因此頁面高度由「window.innerHeight」或$(window).height()計算得出。已關閉。有沒有解決方法?隨時都會發生。計算移動設備上的屏幕高度
0
A
回答
0
使用 'clientWidth' 和 'clientHeight' 代替
0
這取決於如果縮放由視口或不進行。只需使用普通的js來獲得價值。這將大大easyier到CONTROLE:
//Screen
var w = screen.width;
var h = screen.height;
console.log('screen = ',w,' & ',h);
//Screen with ratio
var ratio = window.devicePixelRatio || 1;
var w = screen.width * ratio;
var h = screen.height * ratio;
console.log('screen = ',w,' & ',h);
//Document
//PS document.width & document.height is no longer supported
var w = window.innerWidth
|| document.documentElement.clientWidth //for IE 8 or lower
|| document.body.clientWidth; //for IE 8 or lower
var h = window.innerHeight
|| document.documentElement.clientHeight //for IE 8 or lower
|| document.body.clientHeight; //for IE 8 or lower
console.log('client = ',w,' & ',h);
//Document offset
var w = document.body.offsetWidth
var h = document.body.offsetHeight
console.log('offset = ',w,' & ',h);
//Document fractional offset
var c = document.body.getBoundingClientRect()
console.log(c);
//Scroll
var x = window.scrollX || window.pageXOffset;
var y = window.scrollY || window.pageYOffset;
console.log('scroll = ',x,' & ',y);
享受;)
相關問題
- 1. 在非移動頁面上檢測移動設備屏幕寬度和高度
- 2. 移動屏幕設備寬度
- 3. 如何計算移動設備的寬度和高度
- 4. 屏幕和移動設備上的iframe寬度
- 5. 移動設備上的視口高度
- 6. 移動設備上的時間計算
- 7. 根據屏幕高度計算邊距
- 8. 在移動設備上使用javascript檢測屏幕密度?
- 9. 寬度:100%未在移動設備上填滿屏幕
- 10. 寬高比不同的移動設備屏幕
- 11. 使用主屏幕圖標打破iPhone上的設備高度
- 12. 在Android設備中使行高度與屏幕高度相等
- 13. 移動設備:解決屏幕眩光?
- 14. 移動設備寬度和高度
- 15. 移動設備的屏幕寬度(android和ipod兩者)
- 16. 檢測所有移動設備的屏幕寬度
- 17. 移動設備上的自動屏幕旋轉
- 18. Android屏幕密度計算
- 19. 根據移動設備的設備屏幕選擇佈局
- 20. 如何獲得iOS設備屏幕的高度和寬度
- 21. 獲取設備屏幕的寬度/高度
- 22. CSS - 在屏幕上移動設備的中間
- 23. 小屏幕尺寸/移動設備上的低頻頁腳
- 24. JavaScript在小屏幕移動設備上的可訪問性?
- 25. 移動設備上的全屏幕背景圖像
- 26. 在較小的屏幕/移動設備上刪除Facebook Likebox
- 27. 在移動設備上打開網站時的初始屏幕 -
- 28. 設計的iPhone 5屏幕和設備的屏幕較小
- 29. 如何使頁面適合移動設備上的屏幕寬度?
- 30. 移動設備上的全屏畫布
好吧,這將工作跨瀏覽器和響應? –
據我所知,所有瀏覽器都支持這些屬性 –