Tom Clarke
Tom Clarke

Reputation: 1

Add a delay to jQuery popup?

I am developing a website that has a login popup for those that are not logged in, to get people to register or log in. However, the popup shows immediately upon the website loading, and I want either:

  1. A time delay (e.g. 5000ms)
  2. A scroll delay (e.g. the user scrolls to 50% down the page, and the popup shows)

This is the code for the popup from my developer. I've looked on StackOverflow on how to do it but with no luck, and I'm not great with jQuery etc.

If anyone could provide the complete code for me to test, I'd really appreciate it!

Many thanks in advance.

jQuery(document).ready(function($) {
if (!$('body').hasClass("logged-in")) {
         $.pgwModal({
            titleBar: false,
            target: '#rehub-login-popup',
            mainClassName : 'pgwModal re-user-popup-wrap',
         });
         $('.re-user-popup-wrap .rehub-errors').html('');
}
});
</script>```

Upvotes: 0

Views: 46

Answers (1)

Atul Rajput
Atul Rajput

Reputation: 4178

just wrap your code in Settimeout after document ready, like this

$(document).ready(function(){
  setTimeout(function(){
    alert("Code written here will execute after 5 secodns");
    //write your code here.
  },5000);
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

Upvotes: 1

Related Questions