Question

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,

Était-ce utile?

La solution

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);

    });
});
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top