Bläddra i källkod

地图自动适应大小

DR/4DAGE 3 år sedan
förälder
incheckning
928e9ac161
2 ändrade filer med 14 tillägg och 9 borttagningar
  1. 2 2
      Map/index.html
  2. 12 7
      Map/map.js

+ 2 - 2
Map/index.html

@@ -61,10 +61,10 @@
 
 <body>
     <div id="container">
-        <button id="fun">开始</button>
+        <!-- <button id="fun">开始</button>
         <button id="fun1">暂停</button>
         <button id="fun2">继续</button>
-        <button id="fun3">结束</button>
+        <button id="fun3">结束</button> -->
         <div id="font">
         </div>
     </div>

+ 12 - 7
Map/map.js

@@ -139,10 +139,10 @@ function intervalFun(){
             if(index==line.length-2){
                 clear()
             }
-          
+            setFontsize()
             j++;
         }
-    },1000);
+    },300);
     console.log("interval",interval)
 }
 function addStr(str){
@@ -155,11 +155,16 @@ function addStr(str){
         var txt=document.createTextNode(str);
         txtdiv.appendChild(txt);
     }
-    var width=(window.innerWidth-txtdiv.clientWidth)/2;
-
-    var left=(width/window.innerWidth)*100+"%";
-    let styleStr="position: absolute;z-index: 100;bottom: 10%;background-color:rgba(157,96,34,0.5);color:white;left:"+left
-    txtdiv.setAttribute('style',styleStr);
+    setFontsize()
+}
+//字体自动大小适应
+function setFontsize(){
+    var txtdiv=document.getElementById("font");
+    let width=(window.innerWidth-txtdiv.clientWidth)/2;
+    let fontsize=14/1920 *window.innerWidth;
+     var left=(width/window.innerWidth)*100+"%";
+     let styleStr="position: absolute;z-index: 100;bottom: 10%;background-color:rgba(157,96,34,0.5);color:white;left:"+left+";font-size:"+fontsize+"px"
+     txtdiv.setAttribute('style',styleStr);
 }
 //清除
 function clear(){