1
A
回答
3
你可以檢查視口的寬度和高度,看看哪一個是較大的:
var isLandscapeMode = window.innerWidth > window.innerHeight;
if (isLandscapeMode) {
// fit page to wide orientation here...
}
有關移動設備的視口尺寸的更深入的討論,請參閱 http://www.quirksmode.org/mobile/viewports2.html
(更新代碼)
1
您可以這樣做...
var currOrientation= '';
/************************
* Changes the (obj) element's class, to
* -vrt (vertical)
* -hrz (horizontal)
* depending on its width
*************************/
var orientation = function(obj){
var w = getWidth(),
h = getHeight();
if(w <= h && currOrientation !== 'vrt'){
obj.className = 'vrt';
currOrientation = 'vrt';
}
else if(currOrientation !== 'hrz') {
obj.className = 'hrz';
currOrientation = 'hrz';
}
}
/************************
* Binding a repeating timer
************************/
var orientationINIT = function() {
var content;
if((content = document.getElementsByTagName('body')[0]) != undefined){
orientation(content);
var Orient = setInterval(function() {
orientation(content);
}, 500); //each 500ms a call for orientation change
}
}
orientationINIT應該被稱爲上頁面加載或DOM完成(或在頁面的底部)
其中的getHeight()和的getWidth()應該是在數返回窗口的寬度/高度簡單的功能形成。
相關問題
- 1. 無法檢測負載方向 - iPad
- 2. UIWebView電話鏈接iphone上的檢測
- 3. 用CTCallCenter檢測iOS上的電話(Swift)
- 4. Azure上的負載測試
- 5. 使用傳感器檢測iPhone指向的電流方向
- 6. 檢測電腦的方法
- 7. 檢測爲雙方向上和向右C++,向上箭頭
- 8. 檢測電話目前的電話iphone objective c
- 9. 檢測負數
- 10. 負載測試的方法iOS應用
- 11. 檢測iPhone中的電話呼叫
- 12. 檢測傳入的電話呼叫
- 13. 如何檢測FileReader負載結束?
- 14. 跨域iframe內容負載檢測
- 15. ASP.NET負載均衡器IP檢測
- 16. 檢測Windows Phone的方向
- 17. 爲什麼在負載的角度出現3次時向工廠打電話?
- 18. 禁用方向但檢測方向
- 19. 負載測試vuser負載亞軍11
- 20. 檢測我的應用程序是否在電話上運行
- 21. 如何檢測Android上的電話不活動
- 22. 帶電話的Android 4.x方向
- 23. 負載測試工具的負載測試能力
- 24. Exchange路由代理檢測電子郵件的方向
- 25. 檢測WhatsApp電話和暫停ExoPlayer
- 26. 檢測設備是否支持電話?
- 27. UITextView檢測緊急電話號碼(112)
- 28. 緊急電話號碼檢測
- 29. Android電話管理器檢測SIM卡
- 30. 負向預測的例外
+1好看又簡單:) – walialu 2011-08-17 13:18:05