日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > vue >内容正文

vue

vue移动端html5页面根据屏幕适配的四种解决方法

發布時間:2023/12/10 vue 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 vue移动端html5页面根据屏幕适配的四种解决方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

最近做了兩個關于h5頁面對接公眾號的項目,不得不提打開微信瀏覽器內置地圖導航的功能確實有點惡心。下次想起來了的話,進行總結分享一下如何處理。在vue移動端h5頁面當中,其中適配是經常會遇到的問題,這塊主要有死個方法可以適用。
方法一:引入淘寶開源的可伸縮布局方案
引入淘寶開源的可伸縮布局方案:https://github.com/amfe/lib-flexible(此處可點擊)

淘寶的其實也和viewport的有點像,但是它主要是根據設備設備像素比設置scale的值,保持視口device-width始終等于設備物理像素,屏幕大小動態計算根字體大小,具體是將屏幕劃分為10等分。這塊也可以直接用js實現,后面會提到

具體引入和使用方法,移步github查看,非常詳細。

方法二:viewport 的使用

github里邊,有提到 viewport 的使用。我感覺這篇文章關于viewport 的介紹特別詳細,包括比例、是否縮放等的屬性介紹特別的詳細,雖然文章的內容一大片的字看起來很多,但是請耐心看完,都是干貨能很好的讓你認識viewport。如果比較著急,請繼續往下看總結圖吧
https://blog.csdn.net/qq_43248623/article/details/107187104
關于 viewport 的,這塊直接引用上面文章的內容,我感覺也是最干脆最直接的總結了吧

方法三:使用js+viewport動態設置手動適配rem

我的編輯器是vscode,添加了插件cssrem自動轉換

index.html

<!DOCTYPE html> <html><head><meta charset="utf-8"><!-- <meta name="viewport" content="width=device-width,initial-scale=1.0"> --><meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" /><!-- 啟用360瀏覽器的極速模式(webkit) --><meta name="renderer" content="webkit"><!-- 避免IE使用兼容模式 --><meta http-equiv="X-UA-Compatible" content="IE=edge"><!-- 針對手持設備優化,主要是針對一些老的不識別viewport的瀏覽器,比如黑莓 --><meta name="HandheldFriendly" content="true"><!-- 微軟的老式瀏覽器 --><meta name="MobileOptimized" content="320"><!-- uc強制豎屏 --><meta name="screen-orientation" content="portrait"><!-- QQ強制豎屏 --><meta name="x5-orientation" content="portrait"><!-- UC強制全屏 --><meta name="full-screen" content="yes"><!-- QQ強制全屏 --><meta name="x5-fullscreen" content="true"><!-- UC應用模式 --><meta name="browsermode" content="application"><!-- QQ應用模式 --><meta name="x5-page-mode" content="app"><!-- windows phone 點擊無高光 --><meta name="msapplication-tap-highlight" content="no"><meta content="telephone=no" name="format-detection" /><meta name="huaban" content="nopin" /><link rel="icon" type="image/x-icon" href="/favicon.ico" rel="external nofollow" ><title>新茶飲</title><script src="/config.js"></script><script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script></head><body><div id="app"></div><!-- 在iphone 5 中1rem=16px; html font-size =16px=1rem;--><script>//得到手機屏幕的寬度let htmlWidth = document.documentElement.clientWidth || document.body.clientWidth;console.log('htmlWidth',htmlWidth)//得到html的Dom元素let htmlDom = document.getElementsByTagName('html')[0];// if(htmlWidth>640){//超過640大小的,字體根部都是16px// htmlWidth=640;// console.log('htmlWidth-true',htmlWidth)// }//設置根元素字體大小htmlDom.style.fontSize = htmlWidth / 40 + 'px';</script></body> </html>

方法四:根據css的媒體查詢動態設置根部html字體大小

html {font-size: 625%; /*100 ÷ 16 × 100% = 625%*/} @media screen and (min-width:360px) and (max-width:374px) and (orientation:portrait) {html { font-size: 703%; } } @media screen and (min-width:375px) and (max-width:383px) and (orientation:portrait) {html { font-size: 732.4%; } } @media screen and (min-width:384px) and (max-width:399px) and (orientation:portrait) {html { font-size: 750%; } } @media screen and (min-width:400px) and (max-width:413px) and (orientation:portrait) {html { font-size: 781.25%; } } @media screen and (min-width:414px) and (max-width:431px) and (orientation:portrait){html { font-size: 808.6%; } } @media screen and (min-width:432px) and (max-width:479px) and (orientation:portrait){html { font-size: 843.75%; } }

總結

以上所述是小編給大家介紹的vue移動端html5頁面根據屏幕適配的四種解決方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對我的支持!

總結

以上是生活随笔為你收集整理的vue移动端html5页面根据屏幕适配的四种解决方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。