Set delay or timeout before initializing









up vote
1
down vote

favorite












I'm working with a script that needs to delay (or have a setTimeout) before any animation loads or initializes, but can't seem to figure out where to put it.



As for delay, if I'm not mistaken, this is used mainly with jquery...So for example: $('id or class here').delay(2000); ...Correct?



As for the setTimeout, if I'm not mistaken, it would be with javascript correct? If so, wouldn't it look something similar to this: setTimeout(function () function_name,2000); or a slightly different variation of that?



Regardless of these two approaches and trying to add it where I think it should go (using either variations mentioned above), for some reason it just doesn't work right. The console isn't really helping either to check for errors.



In a nutshell, I'm trying to set a delay of 2s (2000ms) before anything starts or initializes.



JS CODE (Where I believe the issue lies):



$(document).ready(function() 
// Additional code here...
// start
BG.init();

// Additional code here...

});









share|improve this question























  • you can also use setTimeOut like this: setTimeout(function_name,2000);
    – Giovanni Perillo
    Mar 23 '16 at 21:23










  • Correct, this is a slightly different variation of setTimeout that I have also used....I'm just not sure where to place it.
    – Michael
    Mar 23 '16 at 21:24






  • 1




    can you isolate the code you're asking about in a another little code block? that should help people read it better
    – JordanHendrix
    Mar 23 '16 at 21:24










  • What console errors are you returning
    – luke_mclachlan
    Mar 23 '16 at 21:27










  • One mentioned that BG.init isn't a function - most of the time though, there were no errors that were displaying... :/
    – Michael
    Mar 23 '16 at 21:30














up vote
1
down vote

favorite












I'm working with a script that needs to delay (or have a setTimeout) before any animation loads or initializes, but can't seem to figure out where to put it.



As for delay, if I'm not mistaken, this is used mainly with jquery...So for example: $('id or class here').delay(2000); ...Correct?



As for the setTimeout, if I'm not mistaken, it would be with javascript correct? If so, wouldn't it look something similar to this: setTimeout(function () function_name,2000); or a slightly different variation of that?



Regardless of these two approaches and trying to add it where I think it should go (using either variations mentioned above), for some reason it just doesn't work right. The console isn't really helping either to check for errors.



In a nutshell, I'm trying to set a delay of 2s (2000ms) before anything starts or initializes.



JS CODE (Where I believe the issue lies):



$(document).ready(function() 
// Additional code here...
// start
BG.init();

// Additional code here...

});









share|improve this question























  • you can also use setTimeOut like this: setTimeout(function_name,2000);
    – Giovanni Perillo
    Mar 23 '16 at 21:23










  • Correct, this is a slightly different variation of setTimeout that I have also used....I'm just not sure where to place it.
    – Michael
    Mar 23 '16 at 21:24






  • 1




    can you isolate the code you're asking about in a another little code block? that should help people read it better
    – JordanHendrix
    Mar 23 '16 at 21:24










  • What console errors are you returning
    – luke_mclachlan
    Mar 23 '16 at 21:27










  • One mentioned that BG.init isn't a function - most of the time though, there were no errors that were displaying... :/
    – Michael
    Mar 23 '16 at 21:30












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I'm working with a script that needs to delay (or have a setTimeout) before any animation loads or initializes, but can't seem to figure out where to put it.



As for delay, if I'm not mistaken, this is used mainly with jquery...So for example: $('id or class here').delay(2000); ...Correct?



As for the setTimeout, if I'm not mistaken, it would be with javascript correct? If so, wouldn't it look something similar to this: setTimeout(function () function_name,2000); or a slightly different variation of that?



Regardless of these two approaches and trying to add it where I think it should go (using either variations mentioned above), for some reason it just doesn't work right. The console isn't really helping either to check for errors.



In a nutshell, I'm trying to set a delay of 2s (2000ms) before anything starts or initializes.



JS CODE (Where I believe the issue lies):



$(document).ready(function() 
// Additional code here...
// start
BG.init();

// Additional code here...

});









share|improve this question















I'm working with a script that needs to delay (or have a setTimeout) before any animation loads or initializes, but can't seem to figure out where to put it.



As for delay, if I'm not mistaken, this is used mainly with jquery...So for example: $('id or class here').delay(2000); ...Correct?



As for the setTimeout, if I'm not mistaken, it would be with javascript correct? If so, wouldn't it look something similar to this: setTimeout(function () function_name,2000); or a slightly different variation of that?



Regardless of these two approaches and trying to add it where I think it should go (using either variations mentioned above), for some reason it just doesn't work right. The console isn't really helping either to check for errors.



In a nutshell, I'm trying to set a delay of 2s (2000ms) before anything starts or initializes.



JS CODE (Where I believe the issue lies):



$(document).ready(function() 
// Additional code here...
// start
BG.init();

// Additional code here...

});






javascript jquery html5 delay delayed-execution






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 8:23









Flimzy

36.6k96496




36.6k96496










asked Mar 23 '16 at 21:20









Michael

5721413




5721413











  • you can also use setTimeOut like this: setTimeout(function_name,2000);
    – Giovanni Perillo
    Mar 23 '16 at 21:23










  • Correct, this is a slightly different variation of setTimeout that I have also used....I'm just not sure where to place it.
    – Michael
    Mar 23 '16 at 21:24






  • 1




    can you isolate the code you're asking about in a another little code block? that should help people read it better
    – JordanHendrix
    Mar 23 '16 at 21:24










  • What console errors are you returning
    – luke_mclachlan
    Mar 23 '16 at 21:27










  • One mentioned that BG.init isn't a function - most of the time though, there were no errors that were displaying... :/
    – Michael
    Mar 23 '16 at 21:30
















  • you can also use setTimeOut like this: setTimeout(function_name,2000);
    – Giovanni Perillo
    Mar 23 '16 at 21:23










  • Correct, this is a slightly different variation of setTimeout that I have also used....I'm just not sure where to place it.
    – Michael
    Mar 23 '16 at 21:24






  • 1




    can you isolate the code you're asking about in a another little code block? that should help people read it better
    – JordanHendrix
    Mar 23 '16 at 21:24










  • What console errors are you returning
    – luke_mclachlan
    Mar 23 '16 at 21:27










  • One mentioned that BG.init isn't a function - most of the time though, there were no errors that were displaying... :/
    – Michael
    Mar 23 '16 at 21:30















you can also use setTimeOut like this: setTimeout(function_name,2000);
– Giovanni Perillo
Mar 23 '16 at 21:23




you can also use setTimeOut like this: setTimeout(function_name,2000);
– Giovanni Perillo
Mar 23 '16 at 21:23












Correct, this is a slightly different variation of setTimeout that I have also used....I'm just not sure where to place it.
– Michael
Mar 23 '16 at 21:24




Correct, this is a slightly different variation of setTimeout that I have also used....I'm just not sure where to place it.
– Michael
Mar 23 '16 at 21:24




1




1




can you isolate the code you're asking about in a another little code block? that should help people read it better
– JordanHendrix
Mar 23 '16 at 21:24




can you isolate the code you're asking about in a another little code block? that should help people read it better
– JordanHendrix
Mar 23 '16 at 21:24












What console errors are you returning
– luke_mclachlan
Mar 23 '16 at 21:27




What console errors are you returning
– luke_mclachlan
Mar 23 '16 at 21:27












One mentioned that BG.init isn't a function - most of the time though, there were no errors that were displaying... :/
– Michael
Mar 23 '16 at 21:30




One mentioned that BG.init isn't a function - most of the time though, there were no errors that were displaying... :/
– Michael
Mar 23 '16 at 21:30












2 Answers
2






active

oldest

votes

















up vote
3
down vote



accepted










Where you have this:



$(document).ready(function() {


Put this:



$(document).ready(function() 
setTimeout(function()


And then where you have this:



);

// wrapper for background animation functionality
var BG =


Put this:



 , 2000);
);

// wrapper for background animation functionality
var BG = improve this answer




















  • Thank you VoteyDisciple! I actually tried this, however, I didn't quite have it right - the closing , 2000); I place on the .ready closing tags - weird thing is that doing that didn't display any errors in the console on my end - I used your approach and it seems to be working now! Thank you very much!
    – Michael
    Mar 23 '16 at 21:35

















up vote
0
down vote













There's a lot of 'useless' code for us to help you. Next time share only on a need-to-know bases :)



I've edited your $document.ready block to include the timeout, have a look-see:



$(document).ready(function() 
function initiationProcess()
// setup logo image
BG.logo = new Image();
BG.logo.onload = function()
BG.logo_loaded = true;
BG.showLogo();

// /../ more code /../
// wire ticker listener
Ticker.addListener(BG.tick);
// start
BG.init();
// /../ more code /../


setTimeout(initiationProcess, 2000);
);


Edit:
I'd also like to note that it's considered bad practise (not to mention that it might result in buggy code) to only partly use semicolons in your script file. There's points and counterpoints to using semicolons, but pick a standard and stick to it!






share|improve this answer






















  • Is this a more efficient way? Or is what VoteyDisciple posted the better alternative of the two?
    – Michael
    Mar 23 '16 at 21:39











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f36188892%2fset-delay-or-timeout-before-initializing%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote



accepted










Where you have this:



$(document).ready(function() {


Put this:



$(document).ready(function() 
setTimeout(function()


And then where you have this:



);

// wrapper for background animation functionality
var BG =


Put this:



 , 2000);
);

// wrapper for background animation functionality
var BG = improve this answer




















  • Thank you VoteyDisciple! I actually tried this, however, I didn't quite have it right - the closing , 2000); I place on the .ready closing tags - weird thing is that doing that didn't display any errors in the console on my end - I used your approach and it seems to be working now! Thank you very much!
    – Michael
    Mar 23 '16 at 21:35














up vote
3
down vote



accepted










Where you have this:



$(document).ready(function() {


Put this:



$(document).ready(function() 
setTimeout(function()


And then where you have this:



);

// wrapper for background animation functionality
var BG =


Put this:



 , 2000);
);

// wrapper for background animation functionality
var BG = improve this answer




















  • Thank you VoteyDisciple! I actually tried this, however, I didn't quite have it right - the closing , 2000); I place on the .ready closing tags - weird thing is that doing that didn't display any errors in the console on my end - I used your approach and it seems to be working now! Thank you very much!
    – Michael
    Mar 23 '16 at 21:35












up vote
3
down vote



accepted







up vote
3
down vote



accepted






Where you have this:



$(document).ready(function() 


Put this:



$(document).ready(function() 
setTimeout(function()


And then where you have this:



);

// wrapper for background animation functionality
var BG =


Put this:



 , 2000);
);

// wrapper for background animation functionality
var BG = improve this answer












Where you have this:



$(document).ready(function() 


Put this:



$(document).ready(function() 
setTimeout(function()


And then where you have this:



);

// wrapper for background animation functionality
var BG =


Put this:



 , 2000);
);

// wrapper for background animation functionality
var BG = improve this answer












share, 2000); I place on the .ready closing tags - weird thing is that doing that didn't display any errors in the console on my end - I used your approach and it seems to be working now! Thank you very much!
– Michael
Mar 23 '16 at 21:35






















Thank you VoteyDisciple! I actually tried this, however, I didn't quite have it right - the closing , 2000); I place on the .ready closing tags - weird thing is that doing that didn't display any errors in the console on my end - I used your approach and it seems to be working now! Thank you very much!
– Michael
Mar 23 '16 at 21:35




Thank you VoteyDisciple! I actually tried this, however, I didn't quite have it right - the closing , 2000); I place on the .ready closing tags - weird thing is that doing that didn't display any errors in the console on my end - I used your approach and it seems to be working now! Thank you very much!
– Michael
Mar 23 '16 at 21:35












up vote
0
down vote













There's a lot of 'useless' code for us to help you. Next time share only on a need-to-know bases :)



I've edited your $document.ready block to include the timeout, have a look-see:



$(document).ready(function() 
function initiationProcess()
// setup logo image
BG.logo = new Image();
BG.logo.onload = function()
BG.logo_loaded = true;
BG.showLogo();

// /../ more code /../
// wire ticker listener
Ticker.addListener(BG.tick);
// start
BG.init();
// /../ more code /../


setTimeout(initiationProcess, 2000);
);


Edit:
I'd also like to note that it's considered bad practise (not to mention that it might result in buggy code) to only partly use semicolons in your script file. There's points and counterpoints to using semicolons, but pick a standard and stick to it!






share|improve this answer






















  • Is this a more efficient way? Or is what VoteyDisciple posted the better alternative of the two?
    – Michael
    Mar 23 '16 at 21:39















up vote
0
down vote













There's a lot of 'useless' code for us to help you. Next time share only on a need-to-know bases :)



I've edited your $document.ready block to include the timeout, have a look-see:



$(document).ready(function() 
function initiationProcess()
// setup logo image
BG.logo = new Image();
BG.logo.onload = function()
BG.logo_loaded = true;
BG.showLogo();

// /../ more code /../
// wire ticker listener
Ticker.addListener(BG.tick);
// start
BG.init();
// /../ more code /../


setTimeout(initiationProcess, 2000);
);


Edit:
I'd also like to note that it's considered bad practise (not to mention that it might result in buggy code) to only partly use semicolons in your script file. There's points and counterpoints to using semicolons, but pick a standard and stick to it!






share|improve this answer






















  • Is this a more efficient way? Or is what VoteyDisciple posted the better alternative of the two?
    – Michael
    Mar 23 '16 at 21:39













up vote
0
down vote










up vote
0
down vote









There's a lot of 'useless' code for us to help you. Next time share only on a need-to-know bases :)



I've edited your $document.ready block to include the timeout, have a look-see:



$(document).ready(function() 
function initiationProcess()
// setup logo image
BG.logo = new Image();
BG.logo.onload = function()
BG.logo_loaded = true;
BG.showLogo();

// /../ more code /../
// wire ticker listener
Ticker.addListener(BG.tick);
// start
BG.init();
// /../ more code /../


setTimeout(initiationProcess, 2000);
);


Edit:
I'd also like to note that it's considered bad practise (not to mention that it might result in buggy code) to only partly use semicolons in your script file. There's points and counterpoints to using semicolons, but pick a standard and stick to it!






share|improve this answer














There's a lot of 'useless' code for us to help you. Next time share only on a need-to-know bases :)



I've edited your $document.ready block to include the timeout, have a look-see:



$(document).ready(function() 
function initiationProcess()
// setup logo image
BG.logo = new Image();
BG.logo.onload = function()
BG.logo_loaded = true;
BG.showLogo();

// /../ more code /../
// wire ticker listener
Ticker.addListener(BG.tick);
// start
BG.init();
// /../ more code /../


setTimeout(initiationProcess, 2000);
);


Edit:
I'd also like to note that it's considered bad practise (not to mention that it might result in buggy code) to only partly use semicolons in your script file. There's points and counterpoints to using semicolons, but pick a standard and stick to it!







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 23 '16 at 21:37

























answered Mar 23 '16 at 21:32









Kano

2,51211222




2,51211222











  • Is this a more efficient way? Or is what VoteyDisciple posted the better alternative of the two?
    – Michael
    Mar 23 '16 at 21:39

















  • Is this a more efficient way? Or is what VoteyDisciple posted the better alternative of the two?
    – Michael
    Mar 23 '16 at 21:39
















Is this a more efficient way? Or is what VoteyDisciple posted the better alternative of the two?
– Michael
Mar 23 '16 at 21:39





Is this a more efficient way? Or is what VoteyDisciple posted the better alternative of the two?
– Michael
Mar 23 '16 at 21:39


















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f36188892%2fset-delay-or-timeout-before-initializing%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

What does pagestruct do in Eviews?

Dutch intervention in Lombok and Karangasem

Channel Islands