Я делаю веб-сайт, и хотя добавление к нему экрана-заставки было бы неплохо и сделало бы веб-сайт намного более привлекательным. Я сделал код для этого, но проблема, текст отображается нормально, но текст не исчезает после установленного времени, которое составляет 1 секунду, он не исчезает , я в основном перепроверил и не заметил ошибки, а когда запускаю, он работает и ошибок не выдает.

const splash = document.querySelector('.splash');

document.addEventListener('DOMContentLoaded', (e)=>{
    setTimeout(()=>{
        splash.classList.add('display-none');

    }, 2000);
})
body {
    padding: 0;
    margin: 0;
    background: black;
  }
  .navbar {
    overflow: hidden;
    padding: 5px;
    margin: 0;
    top: 0;
    position: sticky;
    background: black;
    color: white;
    opacity: 85%;
  }
  .navbar-item {
    display: inline-block;
    padding: 5px;
  }
  .left {
    float: left;
    font-weight: bold;
    font-size: xx-large;
  }
  .right {
    float: right;
    font-size: x-large;
  }
  .no-style-link {
    text-decoration: none;
    color: inherit;
  }
  .main-content {
    padding: 10px;
    text-align: center;
  }
  .ytvidcollection {
    padding: 10px;
    background: #6969f8;
  }
  .ytvid {
    padding: 5px;
    background: red;
  }
  .ytvid:hover {
    -ms-transform: scale(1.1);
    transform: scale(1.1);
  }
  .copyright {
    background: #333030;
    color: white;
    text-align: center;
    bottom: 0;
    font-size: x-large;
    padding: 10px;
  }
  #Jothin-kumar {
    font-size: xx-large;
    text-decoration: none;
    color: red;
  }
  #Jothin-kumar:hover {
    text-decoration: underline;
  }
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Karan raj</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>

<div class="splash">
    <h1 class="fade-out">Welcome to My Website!</h1>
</div>

<ul class="navbar">
    <li class="navbar-item left"><a class="no-style-link" href="/">Karan raj</a></li>
    <li class="navbar-item right"><a class="no-style-link" href="/">Home</a></li>
    <li class="navbar-item right"><a class="no-style-link" href="/about">About</a></li>
    <li class="navbar-item right"><a class="no-style-link" href="/contact">Contact</a></li>
</ul>
<div class="main-content">
    <iframe width=75% height="750" src="https://www.youtube.com/embed/gHn85Ytl_4w?controls=0&autoplay=1&modestbranding=1&rel=0" title="Trailer" allow="accelerometer; autoplay; clipboard-write; encrypted-media; picture-in-picture"></iframe>
    <div class="ytvidcollection">
        <iframe class="ytvid" width="560" height="315" src="https://www.youtube.com/embed/pFfOzZ97N2k?rel=0" title="Youtube video - Karan raj" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        <iframe class="ytvid" width="560" height="315" src="https://www.youtube.com/embed/fZrw7x44UUA?rel=0" title="Youtube video - Karan raj" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        <iframe class="ytvid" width="560" height="315" src="https://www.youtube.com/embed/XDUVT25yaYM?rel=0" title="Youtube video - Karan raj" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        <iframe class="ytvid" width="560" height="315" src="https://www.youtube.com/embed/-C7l9q1CSOo?rel=0" title="Youtube video - Karan raj" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        <iframe class="ytvid" width="560" height="315" src="https://www.youtube.com/embed/djoODhumDFk?rel=0" title="Youtube video - Karan raj" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        <iframe class="ytvid" width="560" height="315" src="https://www.youtube.com/embed/rvilf-L2Hhw?rel=0" title="Youtube video - Karan raj" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        <iframe class="ytvid" width="560" height="315" src="https://www.youtube.com/embed/8LnoVbcAPFA?rel=0" title="Youtube video - Karan raj" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        <iframe class="ytvid" width="560" height="315" src="https://www.youtube.com/embed/0MH9ESonkiU?rel=0" title="Youtube video - Karan raj" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        <iframe class="ytvid" width="560" height="315" src="https://www.youtube.com/embed/KJSu_8cialA?rel=0" title="Youtube video - Karan raj" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        <iframe class="ytvid" width="560" height="315" src="https://www.youtube.com/embed/rYcMuSEZOBA?rel=0" title="Youtube video - Karan raj" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        <iframe class="ytvid" width="560" height="315" src="https://www.youtube.com/embed/bSsH_uCwNbQ?rel=0" title="Youtube video - Karan raj" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
    </div>
</div>
<div class="copyright">© Copyright 2022 <a href="https://jothin.tech" id="Jothin-kumar">Jothin kumar</a></div>
</body>
</html>
0
Omar Moustafa 18 Янв 2022 в 17:03
Почему вам все еще нужен тайм-аут после срабатывания «DOMContentLoaded»?
 – 
Spidy
18 Янв 2022 в 17:36
Он должен исчезнуть после загрузки контента, но ожидается, что это будет сделано через 1 с.
 – 
Omar Moustafa
18 Янв 2022 в 17:40

3 ответа

Используя jquery,

document.addEventListener('DOMContentLoaded', (e)=>{
    setTimeout(()=>{
      $(".splash").css("display", "none");
    }, 2000);
})
0
Spidy 18 Янв 2022 в 17:22
Тоже самое :( не знаю что делать
 – 
Omar Moustafa
18 Янв 2022 в 17:34

Вы добавляете класс display-none, но он нигде не включен в ваш CSS.

Просто добавив это в свой CSS, вы должны это исправить:

.display-none {
  display: none;
}
const splash = document.querySelector('.splash');

document.addEventListener('DOMContentLoaded', (e)=>{
    setTimeout(()=>{
        splash.classList.add('display-none');

    }, 2000);
})
body {
    padding: 0;
    margin: 0;
    background: black;
}

.splash {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  overflow: hidden;
  background-color: white;
  z-index: 10;
  
  display: flex;
  align-items: center;
  justify-content: center;
}

.display-none {
  display: none;
}

.navbar {
  overflow: hidden;
  padding: 5px;
  margin: 0;
  top: 0;
  position: sticky;
  background: black;
  color: white;
  opacity: 85%;
}

.navbar-item {
  display: inline-block;
  padding: 5px;
}

.left {
  float: left;
  font-weight: bold;
  font-size: xx-large;
}

.right {
  float: right;
  font-size: x-large;
}

.no-style-link {
  text-decoration: none;
  color: inherit;
}

.main-content {
  padding: 10px;
  text-align: center;
}

.ytvidcollection {
  padding: 10px;
  background: #6969f8;
}

.ytvid {
  padding: 5px;
  background: red;
}

.ytvid:hover {
  -ms-transform: scale(1.1);
  transform: scale(1.1);
}

.copyright {
  background: #333030;
  color: white;
  text-align: center;
  bottom: 0;
  font-size: x-large;
  padding: 10px;
}

#Jothin-kumar {
  font-size: xx-large;
  text-decoration: none;
  color: red;
}

#Jothin-kumar:hover {
  text-decoration: underline;
}
<div class="splash">
    <div>Welcome to My Website!</div>
</div>

<ul class="navbar">
    <li class="navbar-item left"><a class="no-style-link" href="/">Karan raj</a></li>
    <li class="navbar-item right"><a class="no-style-link" href="/">Home</a></li>
    <li class="navbar-item right"><a class="no-style-link" href="/about">About</a></li>
    <li class="navbar-item right"><a class="no-style-link" href="/contact">Contact</a></li>
</ul>
<div class="main-content">
    <iframe width=75% height="750" src="https://www.youtube.com/embed/gHn85Ytl_4w?controls=0&autoplay=1&modestbranding=1&rel=0" title="Trailer" allow="accelerometer; autoplay; clipboard-write; encrypted-media; picture-in-picture"></iframe>
    <div class="ytvidcollection">
        <iframe class="ytvid" width="560" height="315" src="https://www.youtube.com/embed/pFfOzZ97N2k?rel=0" title="Youtube video - Karan raj" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        <iframe class="ytvid" width="560" height="315" src="https://www.youtube.com/embed/fZrw7x44UUA?rel=0" title="Youtube video - Karan raj" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        <iframe class="ytvid" width="560" height="315" src="https://www.youtube.com/embed/XDUVT25yaYM?rel=0" title="Youtube video - Karan raj" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        <iframe class="ytvid" width="560" height="315" src="https://www.youtube.com/embed/-C7l9q1CSOo?rel=0" title="Youtube video - Karan raj" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        <iframe class="ytvid" width="560" height="315" src="https://www.youtube.com/embed/djoODhumDFk?rel=0" title="Youtube video - Karan raj" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        <iframe class="ytvid" width="560" height="315" src="https://www.youtube.com/embed/rvilf-L2Hhw?rel=0" title="Youtube video - Karan raj" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        <iframe class="ytvid" width="560" height="315" src="https://www.youtube.com/embed/8LnoVbcAPFA?rel=0" title="Youtube video - Karan raj" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        <iframe class="ytvid" width="560" height="315" src="https://www.youtube.com/embed/0MH9ESonkiU?rel=0" title="Youtube video - Karan raj" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        <iframe class="ytvid" width="560" height="315" src="https://www.youtube.com/embed/KJSu_8cialA?rel=0" title="Youtube video - Karan raj" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        <iframe class="ytvid" width="560" height="315" src="https://www.youtube.com/embed/rYcMuSEZOBA?rel=0" title="Youtube video - Karan raj" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        <iframe class="ytvid" width="560" height="315" src="https://www.youtube.com/embed/bSsH_uCwNbQ?rel=0" title="Youtube video - Karan raj" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
    </div>
</div>
0
Ryan Walls 18 Янв 2022 в 20:06
Тоже самое :( не знаю что делать
 – 
Omar Moustafa
18 Янв 2022 в 17:34
Это определенно работает для меня. Я отредактировал свой вопрос, чтобы показать рабочий код. Я сделал заставку более очевидной с помощью некоторых настроек CSS, чтобы ее было легче увидеть.
 – 
Ryan Walls
18 Янв 2022 в 20:08
Хорошо, спасибо за помощь, Райан Уоллс. Очень ценю, братан.
 – 
Omar Moustafa
19 Янв 2022 в 06:27
const splash = document.querySelector('.splash');

document.addEventListener('DOMContentLoaded', (e)=>{
    setTimeout(()=>{
        splash.classList.add('display-none');

    }, 2000);
})
body {
    padding: 0;
    margin: 0;
    background: black;
}

.splash {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  overflow: hidden;
  background-color: white;
  z-index: 10;
  
  display: flex;
  align-items: center;
  justify-content: center;
}

.display-none {
  display: none;
}

.navbar {
  overflow: hidden;
  padding: 5px;
  margin: 0;
  top: 0;
  position: sticky;
  background: black;
  color: white;
  opacity: 85%;
}

.navbar-item {
  display: inline-block;
  padding: 5px;
}

.left {
  float: left;
  font-weight: bold;
  font-size: xx-large;
}

.right {
  float: right;
  font-size: x-large;
}

.no-style-link {
  text-decoration: none;
  color: inherit;
}

.main-content {
  padding: 10px;
  text-align: center;
}

.ytvidcollection {
  padding: 10px;
  background: #6969f8;
}

.ytvid {
  padding: 5px;
  background: red;
}

.ytvid:hover {
  -ms-transform: scale(1.1);
  transform: scale(1.1);
}

.copyright {
  background: #333030;
  color: white;
  text-align: center;
  bottom: 0;
  font-size: x-large;
  padding: 10px;
}

#Jothin-kumar {
  font-size: xx-large;
  text-decoration: none;
  color: red;
}

#Jothin-kumar:hover {
  text-decoration: underline;
}
<div class="splash">
    <div>Welcome to My Website!</div>
</div>

<ul class="navbar">
    <li class="navbar-item left"><a class="no-style-link" href="/">Karan raj</a></li>
    <li class="navbar-item right"><a class="no-style-link" href="/">Home</a></li>
    <li class="navbar-item right"><a class="no-style-link" href="/about">About</a></li>
    <li class="navbar-item right"><a class="no-style-link" href="/contact">Contact</a></li>
</ul>
<div class="main-content">
    <iframe width=75% height="750" src="https://www.youtube.com/embed/gHn85Ytl_4w?controls=0&autoplay=1&modestbranding=1&rel=0" title="Trailer" allow="accelerometer; autoplay; clipboard-write; encrypted-media; picture-in-picture"></iframe>
    <div class="ytvidcollection">
        <iframe class="ytvid" width="560" height="315" src="https://www.youtube.com/embed/pFfOzZ97N2k?rel=0" title="Youtube video - Karan raj" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        <iframe class="ytvid" width="560" height="315" src="https://www.youtube.com/embed/fZrw7x44UUA?rel=0" title="Youtube video - Karan raj" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        <iframe class="ytvid" width="560" height="315" src="https://www.youtube.com/embed/XDUVT25yaYM?rel=0" title="Youtube video - Karan raj" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        <iframe class="ytvid" width="560" height="315" src="https://www.youtube.com/embed/-C7l9q1CSOo?rel=0" title="Youtube video - Karan raj" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        <iframe class="ytvid" width="560" height="315" src="https://www.youtube.com/embed/djoODhumDFk?rel=0" title="Youtube video - Karan raj" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        <iframe class="ytvid" width="560" height="315" src="https://www.youtube.com/embed/rvilf-L2Hhw?rel=0" title="Youtube video - Karan raj" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        <iframe class="ytvid" width="560" height="315" src="https://www.youtube.com/embed/8LnoVbcAPFA?rel=0" title="Youtube video - Karan raj" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        <iframe class="ytvid" width="560" height="315" src="https://www.youtube.com/embed/0MH9ESonkiU?rel=0" title="Youtube video - Karan raj" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        <iframe class="ytvid" width="560" height="315" src="https://www.youtube.com/embed/KJSu_8cialA?rel=0" title="Youtube video - Karan raj" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        <iframe class="ytvid" width="560" height="315" src="https://www.youtube.com/embed/rYcMuSEZOBA?rel=0" title="Youtube video - Karan raj" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        <iframe class="ytvid" width="560" height="315" src="https://www.youtube.com/embed/bSsH_uCwNbQ?rel=0" title="Youtube video - Karan raj" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
    </div>
</div>
0
Omar Moustafa 19 Янв 2022 в 06:27