-1

Every time I ask a question here, no matter how dumb it is, I do always learn something. Anyway, I'm hoping to get some more good answers to this one. I'm calling a jquery plugin for a modal on document.ready

<script>
    $(document).ready(function() {
      // Initialize the plugin
      $('#JPO').popup({
        absolute: false,
        autoopen: true
        
      });
      $.fn.popup.defaults.pagecontainer = '#page'
    });
  </script>

it auto opens a modal but I only want the modal to open after either a user scrolls down 400px, or after being on the page for 5 seconds, or on exit (exit intent).

This is the jquery plugin I'm using: https://dev.vast.com/jquery-popup-overlay/

Thanks so much in advance!

  • Does this answer your question? [How to wait 5 seconds with jQuery?](https://stackoverflow.com/questions/1836105/how-to-wait-5-seconds-with-jquery) – desbest Dec 12 '20 at 23:10

2 Answers2

2

use setTimeout() function.

Read More about setTimeout

Sample Code:

setTimeout(
  function() 
  {
    //do something special
  }, 5000);
Rajen Trivedi
  • 1,225
  • 2
  • 5
  • 10
0

I used a combination of setTimeout, and onmouseleave to create my popup.

 <script>      
      function openPopup(){
        $('#JPO').popup({
      autoopen: true,
          detatch: true,
          transition: 'all 1.0s'
    });      
      };
      
      function exitPopup(){
            $('#JPO').popup('show');
            };
       
       function cookiePopup(){
         $('#JPO').popup({
           autoopen: false,
           detatch: true,
           transition: 'all 1.0s'
         });
       };
     
$(document).ready(function(){
  $('.modal-content').hide();
  
  var dialogShown = Cookies.get('dialogShown');
  if (!dialogShown) {
        
        setTimeout(openPopup, {{ section.settings.delay }});
        $(document).mouseleave(function(){
          setTimeout(exitPopup,1050)
        });
    Cookies.set('dialogShown', 1, { expires: 1 });
  }
  else {
    setTimeout(cookiePopup, {{ section.settings.delay }});
  }
});
</script>

I also used a plugin called js-cookie to make my pop-up less annoying to repeat visitors. PS. this is for a shopify section, so it does contain some liquid.

Plugins used: