Answer the question
In order to leave comments, you need to log in
How to create infinite repeat js script?
Help me please !!! There is a JS code that shows notifications and hides them. After opening and showing the last 3 notifications, the code stops. How to make code repeat indefinitely? That is, after the disappearance of 3 blocks, 1 2 3 appeared again and so on endlessly
window.addEventListener("DOMContentLoaded", function() {
function c() {
if (a = b.shift()) a.querySelector(".close").addEventListener("click", function(a) {
a.preventDefault();
d()
}), a.classList.add("show"), e = window.setTimeout(d, 3000) //время просмотра
}
function d() {
window.clearTimeout(e);
a && a.classList.remove("show");
window.setTimeout(c, 2000) //пауза между показами
}
var b = document.querySelectorAll(".parent_popup"),
e, a, b = [].slice.call(b, 0);
window.setTimeout(c, 5000) //пауза перед 1 запуском
});
<div class="parent_popup" >
<div class="popup">
<h1>«Всплывающ 1</h1>
<p>реклама какого-либо продукта, подписная форма, форма регистрации или же форма обратной связи.</p>
<a class="close"title="Закрыть" >X</a>
</div>
</div>
<div class="parent_popup" >
<div class="popup">
<h1>«Второе окно 2</h1>
<p> подписная форма, форма регистрации или же форма обратной связи.</p>
<a class="close"title="Закрыть" >X</a>
</div>
</div>
<div class="parent_popup" >
<div class="popup">
<h1>«Третье окно 3</h1>
<p> подписная форма, форма регистрации или же форма обратной связи.</p>
<a class="close"title="Закрыть" >X</a>
</div>
</div>
Answer the question
In order to leave comments, you need to log in
https://jsfiddle.net/a3pvkhwp/1/
const popup = document.querySelectorAll('.popup');
let counter = 0;
setInterval(function() {
popup[counter].classList.remove('show');
counter++;
counter === popup.length ? counter = 0 : console.log('¯\\_(ツ)_/¯')
popup[counter].classList.add('show');
}, 1000)
I can’t imagine why this is, but hanging the last one on the close button is opening the first one, is it not an option?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question