Browse Source

浏览器缩放

yangc 8 years ago
parent
commit
0859accc17
3 changed files with 27 additions and 15 deletions
  1. 26 13
      app.html
  2. 0 1
      layouts/main.vue
  3. 1 1
      nuxt.config.js

+ 26 - 13
app.html

@@ -9,6 +9,18 @@
   <link rel="stylesheet" type="text/css" href="https://at.alicdn.com/t/font_452262_tnqskb835gs98uxr.css">
   {{ HEAD }}
   <script>
+    var reCreateStyle = function() {
+      var style;
+      if(style=document.getElementById("forhtml")){
+        style.parentNode.removeChild(style);
+      }
+      style = document.createElement("style");
+      style.id="forhtml";
+      document.head.appendChild(style);
+
+      var fontSize =  100.00  * (parseFloat(document.documentElement.clientWidth,10)) / 750.00;
+      style.appendChild(document.createTextNode("html{font-size:"+fontSize+"px !important;}"));
+    };
     var _hmt = _hmt || [];
     (function (w, d) {
       if (/(MSIE)|(Trident)/.test(w.navigator.userAgent)) {
@@ -29,25 +41,26 @@
       var cnzz_protocol = (("https:" == d.location.protocol) ? " https://" : " http://");
       d.write(unescape("%3Cspan id='cnzz_stat_icon_1267002346'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s19.cnzz.com/z_stat.php%3Fid%3D1267002346%26show%3Dpic' type='text/javascript'%3E%3C/script%3E"));
       if (/(iPhone|iPad|Opera Mini|Android.*Mobile|NetFront|PSP|BlackBerry|Windows Phone)/ig.test(w.navigator.userAgent)) {
-        let meta1 = d.createElement('meta')
+//        let meta1 = d.createElement('meta')
 //        let meta2 = d.createElement('meta')
-        let head = d.getElementsByTagName('head')[0]
-        meta1.name = 'viewport'
-        meta1.content = 'width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no'
+//        let head = d.getElementsByTagName('head')[0]
+//        meta1.name = 'viewport'
+//        meta1.content = 'width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no'
 //        meta2['http-equiv'] = 'Cache-Control'
 //        meta2.content = 'no-siteapp'
-        head.appendChild(meta1)
+//        head.appendChild(meta1)
 //        head.appendChild(meta2)
-        var docEl = d.documentElement
+//        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'
-          }
+//          var clientWidth = docEl.clientWidth
+//          if (!clientWidth) return
+//          if (clientWidth >= 750) {
+//            docEl.style.fontSize = '100px'
+//          } else {
+//            docEl.style.fontSize = 100 * (clientWidth / 750) + 'px'
+//          }
+          reCreateStyle();
         }
 //        recalc()
         if (!d.addEventListener) return

+ 0 - 1
layouts/main.vue

@@ -40,7 +40,6 @@
       },
       title () {
         let path = this.$route.path
-        console.log(path)
         if (path === '/product/kind/home') {
           return '电子元器件器件选型参数型号查询器件类别分类大全-优软商城'
         } else if (path.startsWith('/product/kind/')) {

+ 1 - 1
nuxt.config.js

@@ -15,7 +15,7 @@ module.exports = {
       { charset: 'utf-8' },
       { 'http-equiv': 'X-UA-Compatible', content: 'IE=edge,chrome=1' },
       { name: 'render', content: 'webkit' },
-      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
+      { name: 'viewport', content: 'width=device-width, initial-scale=1, user-scalable=no' },
       { name: 'apple-mobile-web-app-capable', content: 'yes' },
       { name: 'MobileOptimized', content: '320' },
       { name: 'HandheldFriendly', content: 'true' },