2

Подскажите пожалуйста, есть код, в котором всплывает уведомление. Как сделать автоматическое закрытие этого уведомления через несколько секунд?

HTML:

<div id="msg_pop">
  <h4>Заголовок</h4>
  Пример модального окна, всплывающего при загрузке сайта.
</div>  

JS:

<script type="text/javascript">
  var delay_popup = 0; var msg_pop = 
  document.getElementById('msg_pop'); 
  setTimeout("document.getElementById('msg_pop').style.display='block'; 
  document.getElementById('msg_pop').className += 'fadeIn';", 
  delay_popup); 
</script>

3 ответа 3

2

Используй тот же setTimeout только вместо значения 'block' поставь 'none' и задержку 3 секунды. setTimeout('твой none', 3000);

0

Загуглите метод setTimeout или почитайте здесь: https://developer.mozilla.org/ru/docs/Web/API/WindowTimers/setTimeout

0

Попробуйте это

var timer=setInterval(function(){
  var obj1 = document.getElementsByClassName("postcell")
  obj1[0].style.display="none";
  clearInterval(timer);
},5000);

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.