移動端 橫屏處理

detectOrient() {
  var width = document.documentElement.clientWidth
  var height = document.documentElement.clientHeight
  var $wrapper = document.getElementById('vhtml')
  var style = ''
  if (width >= height) { // 橫屏
    style += 'width:' + width + 'px' // 注意旋轉後的寬高切換
    style += 'height:' + height + 'px'
    style += '-webkit-transform: rotate(0) transform: rotate(0)'
    style += '-webkit-transform-origin: 0 0'
    style += 'transform-origin: 0 0'
    console.log(1)
  } else { // 豎屏
    style += 'width:' + height + 'px'
    style += 'height:' + width + 'px'
    style += '-webkit-transform: rotate(90deg) transform: rotate(90deg)'
    // 注意旋轉中點的處理
    style += '-webkit-transform-origin: ' + width / 2 + 'px ' + width / 2 + 'px'
    style += 'transform-origin: ' + width / 2 + 'px ' + width / 2 + 'px'
    console.log(2)
  }
  $wrapper.style.cssText = style
},
/* 豎屏 */
@media screen and (orientation:portrait) {
    // 以vw爲單位
}

/* 橫屏 */
@media screen and (orientation:landscape) {
  // 以vh爲單位
}
發佈了132 篇原創文章 · 獲贊 5 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章