浏览代码

Use CSS animations to clean up JS

Andrew Chalkley 9 年之前
父节点
当前提交
ad8a6e94cc
共有 3 个文件被更改,包括 40 次插入21 次删除
  1. 27 3
      front-end/css/style.css
  2. 0 1
      front-end/index.html
  3. 13 17
      front-end/js/app.js

+ 27 - 3
front-end/css/style.css

@@ -14,12 +14,9 @@ body {
 }
 }
 
 
 button {
 button {
-	/* Background: */
 	background-image: linear-gradient(-180deg, #4C98FE 0%, #0664E3 100%);
 	background-image: linear-gradient(-180deg, #4C98FE 0%, #0664E3 100%);
-	/* Sketch doesnt export gradient borders at this point */
 	box-shadow: 0px 0px 1px 0px rgba(0,0,0,0.15);
 	box-shadow: 0px 0px 1px 0px rgba(0,0,0,0.15);
 	border-radius: 3px;
 	border-radius: 3px;
-	/* Button: */
 	font-size: 14px;
 	font-size: 14px;
 	color: #FFFFFF;
 	color: #FFFFFF;
 	letter-spacing: -0.11px;
 	letter-spacing: -0.11px;
@@ -48,6 +45,7 @@ footer {
 	width:100%;
 	width:100%;
 	text-align: center;
 	text-align: center;
 	border-top: 1px solid #EDEAE8;
 	border-top: 1px solid #EDEAE8;
+	background: white;
 }
 }
 
 
 #app {
 #app {
@@ -71,5 +69,31 @@ footer {
 	text-align: right;
 	text-align: right;
 }
 }
 
 
+@keyframes moveLeft {
+    0%   {margin-left: 0px;}
+    100% {margin-left: 160px;}
+}
+
+@keyframes moveBack {
+    0%   {margin-left: 160px;}
+    100% {margin-left: 0px;}
+}
+
+#app.flashing #logo {
+	animation: moveLeft 500ms ease-in;
+	margin-left: 160px;
+}
 
 
+#app.flashing #form {
+	display: none;
+}
+
+#app.finished #logo {
+	animation: moveBack 500ms ease-in;
+	margin-left: 0px;
+}
+
+#app.finished #form {
+	display: inline-block;
+}
 
 

+ 0 - 1
front-end/index.html

@@ -54,7 +54,6 @@
     </div>
     </div>
     
     
     <footer><span id="status"></span></footer>
     <footer><span id="status"></span></footer>
-
     <!-- Javascript -->
     <!-- Javascript -->
     <script src="js/app.js" charset="utf-8"></script>
     <script src="js/app.js" charset="utf-8"></script>
 </body>
 </body>

+ 13 - 17
front-end/js/app.js

@@ -103,7 +103,6 @@ serialScanner.on("error", onError);
  * Updates UI to say it's ready
  * Updates UI to say it's ready
  */
  */
 function readyToFlash() {
 function readyToFlash() {
-    form.style.opacity = 1;
     appStatus.textContent = "Ready";
     appStatus.textContent = "Ready";
     enableInputs();
     enableInputs();
 }
 }
@@ -188,6 +187,7 @@ function flashWithManifest(manifest) {
                 .then((result) => {
                 .then((result) => {
                     new Notification("Flash Finished!");
                     new Notification("Flash Finished!");
                     readyToFlash();
                     readyToFlash();
+                    restoreUI();
                     log.info("Flashed to latest Espruino build!", result);
                     log.info("Flashed to latest Espruino build!", result);
                 });
                 });
         }).catch((error) => {
         }).catch((error) => {
@@ -256,33 +256,29 @@ function updateProgressBar(percent, svg){
 }
 }
 
 
 function prepareUIForFlashing(callback) {
 function prepareUIForFlashing(callback) {
-    let marginLeft = 0;
-    let incrementor = 0.01;
     let percent = 100;
     let percent = 100;
-
-    let centerLeft = (appWrapper.clientWidth - logoWrapper.clientWidth) / 2;
+    appWrapper.classList.remove("finished");
+    appWrapper.classList.add("flashing");
     
     
-    let interval = setInterval(() => {
-        incrementor += 0.015;
-        marginLeft += 1.5 / incrementor;
-        if(marginLeft <= centerLeft) {
-            logoWrapper.style.marginLeft = marginLeft + "px";
-        } else {
-            clearInterval(interval);
-        }
-    }, 10);
-
     let percentInterval = setInterval(() => {
     let percentInterval = setInterval(() => {
         percent -= 1;
         percent -= 1;
-        form.style.opacity = percent / 100;
         updateProgressBar(percent, svg);
         updateProgressBar(percent, svg);
         if(percent === 0) {
         if(percent === 0) {
             clearInterval(percentInterval);
             clearInterval(percentInterval);
-            callback();
+            if(callback) callback();
         }
         }
     }, 1);
     }, 1);
 }
 }
 
 
+function restoreUI(callback) {
+    let percent = 0;
+    appWrapper.classList.remove("flashing");
+    appWrapper.classList.add("finished");
+
+    updateProgressBar(100, svg);
+    if(callback) callback();
+}
+
 /**
 /**
  * Get's manifest list for possibilities for flashing,
  * Get's manifest list for possibilities for flashing,
  * scans serial ports and sets up timer for checking for changes.
  * scans serial ports and sets up timer for checking for changes.