婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > 詳解移動端h5頁面根據屏幕適配的四種方案

詳解移動端h5頁面根據屏幕適配的四種方案

熱門標簽:南昌仁和怎么申請開通400電話 電話機器人電銷系統掙話費 高德地圖標注地點糾錯 平涼地圖標注位置怎么弄 只辦理400電話 如何獲取地圖標注客戶 機器人外呼系統存在哪些能力 拓展地圖標注 電話機器人黑斑馬免費

方法一:引入淘寶開源的可伸縮布局方案

引入淘寶開源的可伸縮布局方案:https://github.com/amfe/lib-flexible(此處可點擊)

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

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

方法二:viewport 的使用

github里邊,有提到  viewport 的使用。我感覺這篇文章關于viewport 的介紹特別詳細,包括比例、是否縮放等的屬性介紹特別的詳細,雖然文章的內容一大片的字看起來很多,但是請耐心看完,都是干貨能很好的讓你認識viewport。如果比較著急,請繼續往下看總結圖吧

https://www.jb51.net/article/149140.htm(此處可點擊)

關于 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">
    <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%; }
}

到此這篇關于詳解移動端h5頁面根據屏幕適配的四種方案的文章就介紹到這了,更多相關h5移動端根據屏幕適配內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關文章,希望大家以后多多支持腳本之家!

標簽:永州 青島 西藏 棗莊 池州 新疆 遼源 漯河

巨人網絡通訊聲明:本文標題《詳解移動端h5頁面根據屏幕適配的四種方案》,本文關鍵詞  詳解,移動,端,頁面,根據,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《詳解移動端h5頁面根據屏幕適配的四種方案》相關的同類信息!
  • 本頁收集關于詳解移動端h5頁面根據屏幕適配的四種方案的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 柘荣县| 淄博市| 博爱县| 舟山市| 龙井市| 玛纳斯县| 兰西县| 新泰市| 永康市| 磐安县| 惠来县| 大兴区| 来宾市| 玉环县| 新蔡县| 镇巴县| 奉贤区| 临夏市| 承德县| 长乐市| 琼结县| 福海县| 南充市| 普安县| 海安县| 金昌市| 永城市| 安远县| 潼关县| 沛县| 渭源县| 怀化市| 浑源县| 来凤县| 泽库县| 景谷| 波密县| 巴中市| 依安县| 宜黄县| 萝北县|