怎么让网页在手机上直接就是横屏显示的?

网页是为手机横屏设计的,如果竖屏显示页面会错乱.

慕田峪7331174
浏览 1638回答 1
1回答

墨色风雨

可以判断,然后提示用户进行旋转if(window.orientation==90||window.orientation==-90){     alert("横屏状态!") }或者监听旋转事件window.onorientationchange = function(){      switch(window.orientation){          case -90:          case 90:              alert("横屏:" + window.orientation);        case 0:          case 180:               alert("竖屏:" + window.orientation);        break;      }  }css的媒介查询也是能判断的@media (orientation: portrait) { } 横屏 @media (orientation: landscape) { }竖屏不过还是有解决方案的:打开页面时通过window.orientation可以判断网页是横屏还是竖屏,如果是竖屏,给整个页面添加样式transform: rotate(90deg);这样,你的页面就显示横屏的效果了。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript