一、head部分的meta标签:
const _this = this window.addEventListener( ‘onorientationchange‘ in window ? ‘orientationchange‘ : ‘resize‘, function () { // if (window.orientation === 180 || window.orientation === 0) { // alert(‘竖屏状态!‘) // } if (window.orientation === 90 || window.orientation === -90) { // alert(‘横屏状态!‘) console.log(‘请使用竖屏进行浏览!‘) } }, false )
css: 基于媒体查询标签 监听 orientation:portrait | landscape
@media (min-width: 480px) and (orientation: landscape) { html::before { width: 100%; height: 100%; z-index: 99999; position: fixed; top: 0; left: 0; content: ‘‘; background: #333; } body:before { background-image: url(‘./assets/images/orientation.png‘); background-repeat: no-repeat; background-size: 100% auto; background-position: 50%; content: ‘‘; height: 200px; width: 100px; z-index: 99999; margin: -140px 0 0 -50px; position: absolute; color: #fff; top: 50%; left: 50%; } body:after { content: ‘\4e3a\4e86\66f4\597d\7684\4f53\9a8c\ff0c\8bf7\5c06\624b\673a\7ad6\8fc7\6765‘; position: absolute; top: 50%; text-align: center; height: 30px; left: 0; font-size: 18px; z-index: 99999; width: 100%; color: #fff; margin-top: 35px; } }
六、使用flex布局效果更佳哦!
原文:https://www.cnblogs.com/365terry/p/14356943.html