监听移动端浏览器事件

  1. //判断屏幕方向
  2. if(window.orientation==90||window.orientation==-90){
  3. alert("横屏状态!")
  4. }
  5. //监听屏幕方向
  6. window.onorientationchange = function(){
  7. switch(window.orientation){
  8. case -90:
  9. case 90:
  10. alert("横屏:" + window.orientation);
  11. case 0:
  12. case 180:
  13. alert("竖屏:" + window.orientation);
  14. break;
  15. }
  16. }

css自动响应适配

  1. <!--css媒介查询判断--
  2. @media (orientation: portrait) { } 横屏
  3. @media (orientation: landscape) { }竖屏