Search code examples
javascriptshadowbox

Shadowbox timing issue


I'm using shadowbox js for showing Flash video in lightbox style popups.

So far it's working but I have this problem:

when the page loads and the user clicks too early on the linked image which should open the shadowbox the swf is loaded directly (and no popup appears). Also, the script seems to stop in this case and never assigns the right clicklistener - so the shadowbox is never shown also on subsequent clicks.

Shadowbox 3.0.1

Anybody has experienced the same issue, any solutions? Thanks.


Solution

  • You didn't post any info on when is the shadowbox first called.

    If my guess is correct, You are running shadowbox in an onload event handler. Try calling it when DOM is ready.

    jQuery:

    $(document).ready(function(){
    //call it here
    });
    

    [EDIT] In response to Your comment.

    If this doesn't help there is only one solution.

    Add this just after the line loading jquery script in head

    <script>
    $('<div></div>')
        .css({width:'100%',height:'100%',
    'position':'fixed','top':'0px',left:'0px',
    'z-index':'10000'})
    .addClass('cover');
    .prependTo('body');
    </script>
    

    The above should be one line, but then it's being cut by the stackoverflow's CSS ;)

    and then $('.cover').remove(); when You are sure everything is loaded.

    I do that when running crazy lots of code on pageload ;)