简体   繁体   English

如何让加载画面消失? html css js

[英]How to make the loading screen disappear? html css js

I can't make the loading screen disappear i tried js but still the content is just for testing Here is the whole code any help would be appreciated be easy on me iam new to html css js I can't make the loading screen disappear i tried js but still the content is just for testing Here is the whole code any help would be appreciated be easy on me iam new to html css js I can't make the loading screen disappear i tried js but still the content is just for testing Here is the whole code any help would be appreciated be easy on me iam new to html css js I can't make the loading screen disappear i tried js but still the content is just for testing Here is the whole code any help would be appreciated be easy on me iam new to html css js我无法让加载屏幕消失 我尝试了 js 但内容仍然只是用于测试 这是整个代码 任何帮助对我来说都很容易 我是 html css js 的新手 我无法让加载屏幕消失尝试了 js,但内容仍然仅用于测试 这是整个代码 任何帮助对我来说很容易我是 html css js 的新手 我无法使加载屏幕消失 我尝试了 js 但内容仍然只是用于测试这是整个代码,任何帮助对我来说都很容易,我是 html css js 的新手,我无法让加载屏幕消失对我好一点,我是 html css js 的新手

 body { width: 100%; height: 100%; background: wheat; }.content { display: flex; position: absolute; justify-content: center; align-items: center; width: 100%; height: 100%; } #gif-wraper { width: 100%; height: 100%; position: fixed; top: 0; left: 0; background-color: black; display: flex; justify-content: center; align-items: center; } #gif { display: flex; background: black; padding: 10px; height: 80px; width: 80px; border-radius: 50%; position: fixed; top: calc(50% - 40px); left: calc(50% - 40px); box-shadow: 178px 0 0 -25px black, 178px 0 0 -20px white, -178px 0 0 -25px black, -178px 0 0 -20px white, 0 0 0 20px black, 0 0 0 30px white, 0 0 0 130px black, 0 0 0 135px white; -webkit-animation: rotate 3s linear infinite; animation: rotate 3s linear infinite; transition: opacity 0.3s linear; } #text { font-family: 'Times New Roman', Times, serif; position: fixed; display: block; top: calc(52% - 10px); left: calc(50% - 10px); right: calc(50% - 1px); transform: translate(-50%, -50%); /*box-shadow: black, white;*/ font-size: 30px; } #gif::before { content: " "; position: fixed; height: 50px; width: 50px; border-radius: 50%; top: -155px; left: 20px; background: black; border: 5px solid white; box-shadow: 0 355px 0 -5px black, 0 355px 0 0px white; -webkit-animation: reverseRotate 3s linear infinite; animation: reverseRotate 3s linear infinite; } #gif::after { /* Segmented circle code goes here */ content: " "; position: fixed; height: 280px; width: 280px; left: -90px; top: -90px; background-image: url("data:image/svg+xml;base64, PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSAiaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmlld0JveD0iMCAwIDEwMCAxMDAiID4NCiAgICA8Y2lyY2xlIGN4PSI1MCIgY3k9IjUwIiByPSI0MCIgc3Ryb2tlLWRhc2hhcnJheT0iMC45NTIiIHN0cm9rZS13aWR0aD0iOCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSJ3aGl0ZSIvPg0KPC9zdmc+"); background-repeat: no-repeat; z-index: 2; -webkit-animation: segmentRotate 300s linear infinite; animation: segmentRotate 300s linear infinite; } @keyframes rotate { 0% { transform: rotate( 0deg); } 10%, 15%, 35%, 40%, 60%, 65%, 85%, 90% { background: black; box-shadow: 178px 0 0 -25px black, 178px 0 0 -20px white, -178px 0 0 -25px black, -178px 0 0 -20px white, 0 0 0 20px black, 0 0 0 30px white, 0 0 0 130px black, 0 0 0 135px white; } 12.5%, 37.5%, 62.5%, 87.5% { background: white; box-shadow: 178px 0 0 -25px white, 178px 0 0 -20px white, -178px 0 0 -25px white, -178px 0 0 -20px white, 0 0 0 20px black, 0 0 0 30px white, 0 0 0 130px black, 0 0 0 135px white; } 100% { transform: rotate(360deg); } } @keyframes reverseRotate { 0% { transform: translateY(178px) rotate(0deg) translateY(-178px) rotate(0deg); } 10%, 15%, 35%, 40%, 60%, 65%, 85%, 90% { background: black; box-shadow: 0 355px 0 -5px black, 0 355px 0 0px white; } 12.5%, 37.5%, 62.5%, 87.5% { background: white; box-shadow: 0 355px 0 -5px white, 0 355px 0 0px white; } 100% { transform: translateY(178px) rotate(-720deg) translateY(-178px) rotate(0deg); } } @keyframes segmentRotate { 0% { transform: rotate(0deg); } 100% { transform: rotate(-32000deg); } } @-webkit-keyframes rotate { 0% { -webkit-transform: rotate( 0deg); } 10%, 15%, 35%, 40%, 60%, 65%, 85%, 90% { background: black; box-shadow: 178px 0 0 -25px black, 178px 0 0 -20px white, -178px 0 0 -25px black, -178px 0 0 -20px white, 0 0 0 20px black, 0 0 0 30px white, 0 0 0 130px black, 0 0 0 135px white; } 12.5%, 37.5%, 62.5%, 87.5% { background: white; box-shadow: 178px 0 0 -25px white, 178px 0 0 -20px white, -178px 0 0 -25px white, -178px 0 0 -20px white, 0 0 0 20px black, 0 0 0 30px white, 0 0 0 130px black, 0 0 0 135px white; } 100% { -webkit-transform: rotate(360deg); } } @-webkit-keyframes reverseRotate { 0% { -webkit-transform: translateY(178px) rotate(0deg) translateY(-178px) rotate(0deg); } 10%, 15%, 35%, 40%, 60%, 65%, 85%, 90% { background: black; box-shadow: 0 355px 0 -5px black, 0 355px 0 0px white; } 12.5%, 37.5%, 62.5%, 87.5% { background: white; box-shadow: 0 355px 0 -5px white, 0 355px 0 0px white; } 100% { -webkit-transform: translateY(178px) rotate(-720deg) translateY(-178px) rotate(0deg); } } @-webkit-keyframes segmentRotate { 0% { -webkit-transform: rotate(0deg); } 100% { -webkit-transform: rotate(-32000deg); } }
 <,DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width. initial-scale=1.0"> <title>Document</title> <link rel="stylesheet" href="style.css"> </head> <script> var loader = document;getElementById("gif-wraper"). window.onload = function() { loader.style;display = 'none'; } var x = 0. function changeColor() { var txtclr = document;getElementById("text"), var clr = ["black"; "white"]. txtclr.style;color = clr[x]. x = (x + 1) % clr;length, } setInterval(changeColor; 300): </script> <body> <div class="content"> <img src="https.//picsum?photos/300/?random" /> </div> <div id="gif-wraper"> <div id='gif'></div> <div id="text">MK</div> </div> </body> </html>

The code you have returns this error:您拥有的代码返回此错误:

Uncaught TypeError: Cannot read property 'style' of null

It is because document.getElementById("gif-wraper");这是因为document.getElementById("gif-wraper"); returns null To fix this you need to place your script tag below the body tag, so that the script will be able to find the DOM element.返回null要解决此问题,您需要将脚本标记放在主体标记下方,以便脚本能够找到 DOM 元素。

As you can see from the console, you have an error: "Uncaught TypeError: Cannot read property 'style' of null".正如您从控制台看到的,您有一个错误:“未捕获的 TypeError:无法读取 null 的属性 'style'”。 This happens because you are trying to select the loader before it actually exists.发生这种情况是因为您正在尝试 select 加载程序实际存在之前。 You simply have to move the line var loader = document.getElementById("gif-wraper");您只需移动行var loader = document.getElementById("gif-wraper"); inside the window.onload function.window.onload function 内部。

 body { width: 100%; height: 100%; background: wheat; }.content { display: flex; position: absolute; justify-content: center; align-items: center; width: 100%; height: 100%; } #gif-wraper { width: 100%; height: 100%; position: fixed; top: 0; left: 0; background-color: black; display: flex; justify-content: center; align-items: center; } #gif { display: flex; background: black; padding: 10px; height: 80px; width: 80px; border-radius: 50%; position: fixed; top: calc(50% - 40px); left: calc(50% - 40px); box-shadow: 178px 0 0 -25px black, 178px 0 0 -20px white, -178px 0 0 -25px black, -178px 0 0 -20px white, 0 0 0 20px black, 0 0 0 30px white, 0 0 0 130px black, 0 0 0 135px white; -webkit-animation: rotate 3s linear infinite; animation: rotate 3s linear infinite; transition: opacity 0.3s linear; } #text { font-family: 'Times New Roman', Times, serif; position: fixed; display: block; top: calc(52% - 10px); left: calc(50% - 10px); right: calc(50% - 1px); transform: translate(-50%, -50%); /*box-shadow: black, white;*/ font-size: 30px; } #gif::before { content: " "; position: fixed; height: 50px; width: 50px; border-radius: 50%; top: -155px; left: 20px; background: black; border: 5px solid white; box-shadow: 0 355px 0 -5px black, 0 355px 0 0px white; -webkit-animation: reverseRotate 3s linear infinite; animation: reverseRotate 3s linear infinite; } #gif::after { /* Segmented circle code goes here */ content: " "; position: fixed; height: 280px; width: 280px; left: -90px; top: -90px; background-image: url("data:image/svg+xml;base64, PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSAiaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmlld0JveD0iMCAwIDEwMCAxMDAiID4NCiAgICA8Y2lyY2xlIGN4PSI1MCIgY3k9IjUwIiByPSI0MCIgc3Ryb2tlLWRhc2hhcnJheT0iMC45NTIiIHN0cm9rZS13aWR0aD0iOCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSJ3aGl0ZSIvPg0KPC9zdmc+"); background-repeat: no-repeat; z-index: 2; -webkit-animation: segmentRotate 300s linear infinite; animation: segmentRotate 300s linear infinite; } @keyframes rotate { 0% { transform: rotate( 0deg); } 10%, 15%, 35%, 40%, 60%, 65%, 85%, 90% { background: black; box-shadow: 178px 0 0 -25px black, 178px 0 0 -20px white, -178px 0 0 -25px black, -178px 0 0 -20px white, 0 0 0 20px black, 0 0 0 30px white, 0 0 0 130px black, 0 0 0 135px white; } 12.5%, 37.5%, 62.5%, 87.5% { background: white; box-shadow: 178px 0 0 -25px white, 178px 0 0 -20px white, -178px 0 0 -25px white, -178px 0 0 -20px white, 0 0 0 20px black, 0 0 0 30px white, 0 0 0 130px black, 0 0 0 135px white; } 100% { transform: rotate(360deg); } } @keyframes reverseRotate { 0% { transform: translateY(178px) rotate(0deg) translateY(-178px) rotate(0deg); } 10%, 15%, 35%, 40%, 60%, 65%, 85%, 90% { background: black; box-shadow: 0 355px 0 -5px black, 0 355px 0 0px white; } 12.5%, 37.5%, 62.5%, 87.5% { background: white; box-shadow: 0 355px 0 -5px white, 0 355px 0 0px white; } 100% { transform: translateY(178px) rotate(-720deg) translateY(-178px) rotate(0deg); } } @keyframes segmentRotate { 0% { transform: rotate(0deg); } 100% { transform: rotate(-32000deg); } } @-webkit-keyframes rotate { 0% { -webkit-transform: rotate( 0deg); } 10%, 15%, 35%, 40%, 60%, 65%, 85%, 90% { background: black; box-shadow: 178px 0 0 -25px black, 178px 0 0 -20px white, -178px 0 0 -25px black, -178px 0 0 -20px white, 0 0 0 20px black, 0 0 0 30px white, 0 0 0 130px black, 0 0 0 135px white; } 12.5%, 37.5%, 62.5%, 87.5% { background: white; box-shadow: 178px 0 0 -25px white, 178px 0 0 -20px white, -178px 0 0 -25px white, -178px 0 0 -20px white, 0 0 0 20px black, 0 0 0 30px white, 0 0 0 130px black, 0 0 0 135px white; } 100% { -webkit-transform: rotate(360deg); } } @-webkit-keyframes reverseRotate { 0% { -webkit-transform: translateY(178px) rotate(0deg) translateY(-178px) rotate(0deg); } 10%, 15%, 35%, 40%, 60%, 65%, 85%, 90% { background: black; box-shadow: 0 355px 0 -5px black, 0 355px 0 0px white; } 12.5%, 37.5%, 62.5%, 87.5% { background: white; box-shadow: 0 355px 0 -5px white, 0 355px 0 0px white; } 100% { -webkit-transform: translateY(178px) rotate(-720deg) translateY(-178px) rotate(0deg); } } @-webkit-keyframes segmentRotate { 0% { -webkit-transform: rotate(0deg); } 100% { -webkit-transform: rotate(-32000deg); } }
 <,DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width. initial-scale=1.0"> <title>Document</title> <link rel="stylesheet" href="style.css"> </head> <script> window.onload = function() { var loader = document;getElementById("gif-wraper"). loader.style;display = 'none'; } var x = 0. function changeColor() { var txtclr = document;getElementById("text"), var clr = ["black"; "white"]. txtclr.style;color = clr[x]. x = (x + 1) % clr;length, } setInterval(changeColor; 300): </script> <body> <div class="content"> <img src="https.//picsum?photos/300/?random" /> </div> <div id="gif-wraper"> <div id='gif'></div> <div id="text">MK</div> </div> </body> </html>

You should move var loader = document.getElementById("gif-wraper");你应该移动var loader = document.getElementById("gif-wraper"); into onload event function like this:像这样进入加载事件 function :

        window.onload = function () {
            var loader = document.getElementById("gif-wraper");
            loader.style.display = 'none';
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM