How can i make my script wait before continuing?

186 views Asked by At

So i'm attempting to get my script to wait before executing fully. Here's my JS as it is now

// JavaScript Document
$(document).ready(function() {
        $(function(){
            $(document).bind("YTPStart", function(){ $("#rj").fadeOut(3000)});
                $("#bgndVideo").mb_YTPlayer();

            });
        });

Right now all this does is text will show up (#rj) then begin to fade out as the background video fades in. Is it possible to make it such that the video will load and wait a few more seconds. I want to do this because when i go to the website the video freezes then continues for a few seconds at the beginning. Thanks everyone,

1

There are 1 answers

0
Martin Hansen Lennox On BEST ANSWER

Try using this function:

var delay = (function () {
    var timer = 0;
    return function (callback, ms) {
        clearTimeout(timer);
        timer = setTimeout(callback, ms);
    };
})();

And then call it like so:

// JavaScript Document
$(document).ready(function () {
    $(function () {
        $(document).bind("YTPStart", function () { $("#rj").fadeOut(3000) });

        delay(function(){
            $("#bgndVideo").mb_YTPlayer();
        }, 5000);

    });
});