通过window.orientation来判断设备横竖屏 function checkOrient() { if (window.orientation == 0 || window.orientation == 180){ var screenOrientation = 'portrait'; } else if (window.orientation == 90 || window.orientation == -90){ var screenOrientation = 'landscape'; } return screenOrientation; } // 添加事件监听 addEventListener('load', function(){ checkOrient(); window.onorientationchange = checkOrient; });
注:landscape是横向,portrait是纵向
转自:http://www.best-html5.net/?p=661