Make pop-up open after a while

1

I have a popup and would like it to open after the user is already a while on a particular link.

My JS looks like this:

 if($('.popup-banner').length > 0) {
    (window.location.href === '/')
    $('.popup-banner .fechar, .popup-banner .link-fechar, .popup-overlay').click(function() {
        $('.popup-overlay, .popup-banner').fadeOut(400);
    });
}

Where do I put the delay ?

    
asked by anonymous 27.03.2018 / 18:58

2 answers

0

Use setTimeout and show the popup with .fadeIn() , like this:

if($('.popup-banner').length > 0) {
    (window.location.href === '/')

    setTimeout(function(){
       $(".popup-banner").fadeIn();
    }, 3000); // 3000 = 3 segundos

    $('.popup-banner .fechar, .popup-banner .link-fechar, .popup-overlay').click(function() {
        $('.popup-overlay, .popup-banner').fadeOut(400);
    });
}

Example:

if($('.popup-banner').length > 0) {
    (window.location.href === '/')
    
    setTimeout(function(){
       $(".popup-banner").fadeIn();
    }, 3000); // 3000 = 3 segundos
    
    $('.popup-banner .fechar, .popup-banner .link-fechar, .popup-overlay').click(function() {
        $('.popup-overlay, .popup-banner').fadeOut(400);
    });
}
.popup-banner{
   display: none;
   background: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>Aguarde3segundos...<divclass="popup-banner">
   pop up
</div>
    
27.03.2018 / 22:41
0

I just kept what will make the element open:

setTimeout( function() {
   $('.popup-overlay, .popup-banner').fadeOut(400);
},3000)

This causes the click function to stop working, since the idea is to open it automatically.

If you want to keep the click, keep your existing code (which only deals with the click) and add this new one, which will do the same thing, however considering ONLY the time.

Note that 3000 is the time in milliseconds.

    
27.03.2018 / 19:12