JAVASCRIPT
VUE
REACT
NODE
ES6
TYPESCRIPT

监听手机端横竖屏

2021. 04. 25    

监听手机端横竖屏

<script>
  window.addEventListener('resize',()=>{
    if(window.orientation=== 180 || window.orientation===0){
      console.log("竖屏")
    }
    if(window.orientation === 90 || window.orientation===-90){
      console.log("横屏")
    }
  })
</script>
<style>
  @media screen and (orientation: portrait){
    /*竖屏*/
  }
  @media screen and (orientation: landscape){
    /*竖屏*/
  }
</style>