E
E
Evij212021-11-22 15:26:28
JavaScript
Evij21, 2021-11-22 15:26:28

There is a modal, it opens on all pages every 30 seconds, how to arrange it so that it opens on the site every 30 seconds?

There is a modal, it opens on all pages every 30 seconds, i.e. how do we go to /contact we open again, how to make it open on the site every 30 seconds?

<div class="elfeika none">
  <div class="elfeika__inner">
    
    <div class="elfeika__content">
      <h1 class="title">
        WAIT!
      </h1>
      <p class="subtitle">Elves want to give YOUR a</p>
      <p class="discount">10% discount</p>
      <p class="first">for your first order</p>
      <div class="bullites">
        <div class="bullites__item">
          <div class="number">1</div>
          <p class="text">Add the product to cart. </p>
        </div>
        <div class="bullites__item">
          <div class="number">2</div>
          <p class="text">Enter coupon code. </p>
        </div>
        <div class="bullites__item">
          <div class="number">3</div>
          <p class="text">And get our discount. </p>
        </div>
      </div>
        <?php echo do_shortcode( '[contact-form-7 id="7835" title="popup"]' ); ?>
<!-- 			<div class="buttoss">
        <button class="buttos no">No, thank you!</button>
        <button class="buttos yes">GET CODE</button>
      </div> -->
    </div>
    <div class="elfeika__bg">
      <img src="https://plagueboost.com/wp-content/themes/plagueboost/assets/img/bg.png" alt="">
    </div>
  </div>
</div>

function block() {
    var elfeika = document.querySelector('.elfeika')
    elfeika.classList.remove('none')
  }
 
setTimeout(block, 20000)



$(document).mouseleave(function(e){
    if (e.clientY < 10) {
        $(".elfeika").fadeIn("fast");
        var elfeika = document.querySelector('.elfeika')
  elfeika.classList.remove('none')
    }    
});
$('.no').click(function(e) {
    if (($(".elfeika").is(':visible')) && (!$(e.target).closest(".elfeika .subtitle").length)) {
        $(".elfeika").remove();
    }
});
  
  
function block1() {
  var yes = document.querySelector('.wpcf7-response-output').textContent
  if (yes == 'Thank you for your message. It was sent successfully.') {
    $(".elfeika").remove();
  }
   
}


$('.yes').on('click', function() {
  setTimeout(block1, 2000)
})

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Litvinenko, 2021-11-22
@AntonLitvinenko

if (window.sessionStorage && window.localStorage) {
  if(!localStorage.getItem('modal','1')) {
    setTimeout(block, 20000);
    localStorage.setItem('modal','1');
  }
}

A
Alexey Dubrovin, 2021-11-22
@alekcena

setTimeout - the function is executed 1 time and cleared.
setInterval - the function is executed periodically. Clearing only through clearInterval

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question