Jelajahi Sumber

【新增】优化动画初始化

PJ568 1 tahun lalu
induk
melakukan
7f8b1533aa
1 mengubah file dengan 5 tambahan dan 10 penghapusan
  1. 5 10
      index.html

+ 5 - 10
index.html

@@ -3,7 +3,7 @@
 <!-- 作者:PJ568 -->
 <!-- 项目地址:https://github.com/PJ-568/markdown.html/ -->
 <!-- 本项目遵循 CC BY-SA 4.0 International 许可协议 -->
-<!-- v 0.9.1 -->
+<!-- v 0.10.0 -->
 
 <head>
   <meta charset="utf-8">
@@ -18,8 +18,6 @@
     // 使用 IIFE 包裹以避免全局变量污染
     (function () {
       // 加载动画相关
-      var loadingBar = document.querySelector('.loading-bar');
-      var progress = document.querySelector('.loading-bar .progress');
       var timer = null;
 
       // 文档解析功能相关
@@ -37,14 +35,10 @@
       // 自定义 PJAX 相关
       const existPushState = (history && history.pushState);
 
-      // 初始化加载动画相关元素
-      function initAni() {
-        loadingBar = document.querySelector('.loading-bar');
-        progress = document.querySelector('.loading-bar .progress');
-      }
-
       // 开始加载动画
       function startLoad() {
+        const loadingBar = document.querySelector('.loading-bar');
+        const progress = document.querySelector('.loading-bar .progress');
         var loadingBarWidth = 20;
         var MAX_LOADING_WIDTH = 95;
 
@@ -65,6 +59,8 @@
 
       // 停止加载动画
       function endLoad() {
+        const loadingBar = document.querySelector('.loading-bar');
+        const progress = document.querySelector('.loading-bar .progress');
         clearInterval(timer);
         progress.style.width = '100%';
         loadingBar.classList.remove('loading');
@@ -318,7 +314,6 @@
         initTranslate();	//// 初始化页面翻译
         initPjax();	//// 初始化 Pjax
         initCostumedPjax();	//// 初始化自定义 PJAX
-        initAni();	//// 初始化加载动画
         if (existPushState) {
           history.pushState({ url: window.location.href, title: document.title, uid: window.location.href }, null, window.location.href);
         }