移动端横竖屏的监听

window.addEventListener(
  'onorientationchange' in window ? 'orientationchange' : 'resize',
  function() {
    if (window.orientation === 90 || window.orientation === -90) {
      Modal.show({ content: '为了您良好使用体验,建议竖屏观看', btnText: '确认' });
    }
    if (window.orientation === 180 || window.orientation === 0) {
      Modal.close();
    }
  },
  false,
);

你可能感兴趣的:(移动端横竖屏的监听)