Browse Source

font-size尺寸适配

yangc 8 years ago
parent
commit
d4b4dc93af
4 changed files with 18 additions and 24 deletions
  1. 16 0
      app.html
  2. 1 3
      components/mobile/MobileHeader.vue
  3. 0 20
      layouts/main.vue
  4. 1 1
      pages/index.vue

+ 16 - 0
app.html

@@ -20,6 +20,22 @@
         appendScript('https://cdn.bootcss.com/html5shiv/r29/html5.min.js')
         appendScript('https://cdn.bootcss.com/html5shiv/r29/html5.min.js')
         appendScript('https://cdn.bootcss.com/js-polyfills/0.1.33/polyfill.min.js')
         appendScript('https://cdn.bootcss.com/js-polyfills/0.1.33/polyfill.min.js')
       }
       }
+      if (/(iPhone|iPad|Opera Mini|Android.*Mobile|NetFront|PSP|BlackBerry|Windows Phone)/ig.test(w.navigator.userAgent)) {
+        var docEl = d.documentElement
+        var resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize'
+        var recalc = function () {
+          var clientWidth = docEl.clientWidth
+          if (!clientWidth) return
+          if (clientWidth >= 750) {
+            docEl.style.fontSize = '100px'
+          } else {
+            docEl.style.fontSize = 100 * (clientWidth / 750) + 'px'
+          }
+        }
+        if (!d.addEventListener) return
+        w.addEventListener(resizeEvt, recalc, false)
+        d.addEventListener('DOMContentLoaded', recalc, false)
+      }
     })(window, document)
     })(window, document)
   </script>
   </script>
 </head>
 </head>

+ 1 - 3
components/mobile/MobileHeader.vue

@@ -10,8 +10,6 @@
 </script>
 </script>
 <style>
 <style>
 .mobile-header{
 .mobile-header{
-  position:fixed;
-  top:0;
   width:100%;
   width:100%;
   height:60px;
   height:60px;
   display:flex;
   display:flex;
@@ -22,7 +20,7 @@
 }
 }
   .mobile-header p{
   .mobile-header p{
     flex:1;
     flex:1;
-    font-size:2.4rem;
+    font-size:.24rem;
     text-align: center;
     text-align: center;
     margin-top:10px;
     margin-top:10px;
   }
   }

+ 0 - 20
layouts/main.vue

@@ -29,26 +29,6 @@
       isMobile: function () {
       isMobile: function () {
         return this.$store.state.option.isMobile
         return this.$store.state.option.isMobile
       }
       }
-    },
-    mounted () {
-      if (this.isMobile) {
-        let doc = document
-        let win = window
-        let docEl = doc.documentElement
-        let resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize'
-        let recalc = function () {
-          let clientWidth = docEl.clientWidth
-          if (!clientWidth) return
-          if (clientWidth >= 640) {
-            docEl.style.fontSize = '100px'
-          } else {
-            docEl.style.fontSize = 100 * (clientWidth / 640) + 'px'
-          }
-        }
-        if (!doc.addEventListener) return
-        win.addEventListener(resizeEvt, recalc, false)
-        doc.addEventListener('DOMContentLoaded', recalc, false)
-      }
     }
     }
   }
   }
 </script>
 </script>

+ 1 - 1
pages/index.vue

@@ -1,7 +1,7 @@
 <template>
 <template>
   <div class="index">
   <div class="index">
     <div v-if="isMobile">
     <div v-if="isMobile">
-      <Home></Home>
+      <!--<Home></Home>-->
     </div>
     </div>
     <div v-else>
     <div v-else>
       <carousel>
       <carousel>