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