Search code examples
javascriptjquerylightbox2

Adding a delayed trigger to lightbox2


I've set up Lightbox2 to make an image pop up on page load by using this code that I found on another post:

<script>$(document).ready(function(){$("#popimg").trigger('click')});</script>

I want to delay the popup and not start immediately on load. What do I need to add to the script to make this work? I can't seem to figure it out.


Solution

  • You can use setTimeout or jQuery's delay

    Here is an example with setTimeout where 2000 is equal to 2 seconds.

    $(document).ready(function() {
      window.setTimeout(function () {
        $("#popimg").trigger('click');
      }, 2000);
    });