vux、h5打包的app如何橫向屏幕?找到一個騷操作

1.vux、h5打包的app如何橫向屏幕?

想說點廢話,欲言又止,迴歸正題,直接看源碼吧

2.源碼如下:vue的寫法
  methods:{
    detectOrient(){
      var width = document.documentElement.clientWidth,
      height = document.documentElement.clientHeight,
      $wrapper = this.$refs.bd,					//改這個東西就得了,獲取容器對象
      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;
    },
    nextView(){
      this.$router.push({path:'/animat',name:'animat', params:{role:this.role, name:'你好'}})
    }
  },
  mounted(){
    var that = this;
    // 利用 CSS3 旋轉 對根容器逆時針旋轉 90 度
        window.onresize = that.detectOrient();
        that.detectOrient();
  }
3.注意事項:

這個操作存在有一些bug,比如loading時並不會跟着旋轉等,只能解決一時之需,如需詳細 傳送門開啓


有幫助的話記得回來三連
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章