https://blog.csdn.net/qq_30682027/article/details/83858542

    根节点直接添加加载效果,在加载完成后删除加载节点

    1. <!DOCTYPE html>
    2. <html>
    3. <head>
    4. <title>11111111</title>
    5. <meta charset="utf-8" />
    6. <meta http-equiv="pragma" content="no-cache">
    7. <meta http-equiv="cache-control" content="no-cache">
    8. <meta http-equiv="expires" content="0">
    9. <meta name="referrer" content="no-referrer">
    10. </head>
    11. <body>
    12. <div id="loading"
    13. style="position: absolute; top: 0; bottom: 0; left: 0; right: 0; display: flex; align-items: center; justify-content: center; overflow: hidden;">
    14. <!-- 加载图片 -->
    15. <img style="width: 100px; height: 100px;" src='.../'>
    16. </div>
    17. <div id="app"></div>
    18. </body>
    19. <script>
    20. var root = document.getElementById('loading');
    21. root.style.height = "100%";
    22. console.log(document.readyState, 1111111111);
    23. document.onreadystatechange = function () {
    24. let string = document.readyState;
    25. console.log(string, 'string');
    26. if (string === 'complete') root.remove()
    27. }
    28. </script>
    29. </html>