淺析vue如何實(shí)現(xiàn)手機(jī)橫屏功能
功能背景
有些需求需要手動(dòng)實(shí)現(xiàn)橫屏功能,比如點(diǎn)擊一個(gè)橫屏的圖標(biāo)將整個(gè)頁面90度翻轉(zhuǎn),再點(diǎn)擊退出橫屏回到正常頁面。
實(shí)現(xiàn)思路
一拿到這個(gè)需求很可能就被嚇到了,但簡單來說,就是點(diǎn)擊橫屏按鈕跳轉(zhuǎn)一個(gè)新頁面,通過 css樣式 的翻轉(zhuǎn)樣式來實(shí)現(xiàn),主要是計(jì)算橫屏的寬高比較麻煩,下面來看具體的代碼實(shí)現(xiàn)。
關(guān)鍵代碼
<view class="box"> <view class="jxcLandscape" :style="{width:newHeight+'px',height:newWidth+'px'}"> <view class="title_H"> <view @click="handleBack" class="image_H"> <img style="width:40rpx;height: 40rpx;margin-right: 8rpx;" src="@/static/screen.png" /> 退出橫屏 </view> </view> <!--主要內(nèi)容區(qū)--> </view> </view>
css 樣式:
.box{ position: relative; width: 100%; height: 100vh; overscroll-behavior: none; } .jxcLandscape{ padding: 10px; transform: rotate(90deg); // 關(guān)鍵代碼 transform-origin: 0% 0%; // 關(guān)鍵代碼 position: absolute; top: 0%; left: 100%; margin-left: 0; }
js 方法:
onLoad(){ let that=this uni.getSystemInfo({ success: function (res) { that.newWidth=res.windowWidth that.tablenewWidth=res.windowWidth-50 if(res.platform=='android'){ this.getStatusBarHeight((height) => { that.barHeight = height that.newHeight=res.windowHeight-that.barHeight }) }else{ // 這是蘋果操作系統(tǒng) that.newHeight=res.windowHeight } } }) }, methods:{ getStatusBarHeight(){ let barHeight = 51 if (uni.getSystemInfoSync().platform == "ios") { // ios {}可傳參 this.callhandler('getStatusBarHeight', "", callBack); } if (uni.getSystemInfoSync().platform == "android") { // Android if (window.webkit) { barHeight = window.webkit.getStatusBarHeight() callBack(barHeight) } } }, callhandler(name, data, callback) { setupWebViewJavascriptBridge(function(bridge) { bridge.callHandler(name, data, callback) }) }, setupWebViewJavascriptBridge(callback) { if (window.WebViewJavascriptBridge) { return callback(window.WebViewJavascriptBridge) } if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback) } window.WVJBCallbacks = [callback] let WVJBIframe = document.createElement('iframe') WVJBIframe.style.display = 'none' WVJBIframe.src = 'https://__bridge_loaded__' document.documentElement.appendChild(WVJBIframe) setTimeout(() => { document.documentElement.removeChild(WVJBIframe) }, 0) } }
到此這篇關(guān)于淺析vue如何實(shí)現(xiàn)手機(jī)橫屏功能的文章就介紹到這了,更多相關(guān)vue手機(jī)橫屏內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Vue項(xiàng)目打包部署的實(shí)戰(zhàn)過程記錄
我們使用nginx部署Vue項(xiàng)目,實(shí)質(zhì)上就是將Vue項(xiàng)目打包后的內(nèi)容同步到nginx指向的文件夾,下面這篇文章主要給大家介紹了關(guān)于Vue項(xiàng)目打包部署的相關(guān)資料,需要的朋友可以參考下2021-09-09vue template當(dāng)中style背景設(shè)置不編譯問題
這篇文章主要介紹了vue template當(dāng)中style背景設(shè)置不編譯問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-04-04使用mint-ui開發(fā)項(xiàng)目的一些心得(分享)
下面小編就為大家?guī)硪黄褂胢int-ui開發(fā)項(xiàng)目的一些心得(分享)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-09-09讓webpack+vue-cil項(xiàng)目不再自動(dòng)打開瀏覽器的方法
今天小編就為大家分享一篇讓webpack+vue-cil項(xiàng)目不再自動(dòng)打開瀏覽器的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-09-09vue中用動(dòng)態(tài)組件實(shí)現(xiàn)選項(xiàng)卡切換效果
本篇文章主要介紹了vue中用動(dòng)態(tài)組件實(shí)現(xiàn)選項(xiàng)卡切換效果,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-03-03VueJS設(shè)計(jì)與實(shí)現(xiàn)之淺響應(yīng)與深響應(yīng)詳解
這篇文章主要為大家介紹了VueJS設(shè)計(jì)與實(shí)現(xiàn)之淺響應(yīng)與深響應(yīng)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08Vue導(dǎo)入excel文件的兩種方式(form表單和el-upload)
最近開發(fā)遇到一個(gè)點(diǎn)擊導(dǎo)入按鈕讓excel文件數(shù)據(jù)導(dǎo)入的需求,下面這篇文章主要給大家介紹了關(guān)于Vue導(dǎo)入excel文件的兩種方式,分別是form表單和el-upload兩種方法,需要的朋友可以參考下2022-11-11