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...
});
javascript jquery html5 delay delayed-execution
|
show 4 more comments
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...
});
javascript jquery html5 delay delayed-execution
you can also usesetTimeOutlike this:setTimeout(function_name,2000);
– Giovanni Perillo
Mar 23 '16 at 21:23
Correct, this is a slightly different variation ofsetTimeoutthat 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
|
show 4 more comments
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...
});
javascript jquery html5 delay delayed-execution
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
javascript jquery html5 delay delayed-execution
edited Nov 11 at 8:23
Flimzy
36.6k96496
36.6k96496
asked Mar 23 '16 at 21:20
Michael
5721413
5721413
you can also usesetTimeOutlike this:setTimeout(function_name,2000);
– Giovanni Perillo
Mar 23 '16 at 21:23
Correct, this is a slightly different variation ofsetTimeoutthat 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
|
show 4 more comments
you can also usesetTimeOutlike this:setTimeout(function_name,2000);
– Giovanni Perillo
Mar 23 '16 at 21:23
Correct, this is a slightly different variation ofsetTimeoutthat 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
|
show 4 more comments
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.readyclosing 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
add a comment |
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!
Is this a more efficient way? Or is whatVoteyDiscipleposted the better alternative of the two?
– Michael
Mar 23 '16 at 21:39
add a comment |
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.readyclosing 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
add a comment |
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.readyclosing 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
add a comment |
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
add a comment , 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
add a comment |
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!
Is this a more efficient way? Or is whatVoteyDiscipleposted the better alternative of the two?
– Michael
Mar 23 '16 at 21:39
add a comment |
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!
Is this a more efficient way? Or is whatVoteyDiscipleposted the better alternative of the two?
– Michael
Mar 23 '16 at 21:39
add a comment |
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!
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!
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 whatVoteyDiscipleposted the better alternative of the two?
– Michael
Mar 23 '16 at 21:39
add a comment |
Is this a more efficient way? Or is whatVoteyDiscipleposted 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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
you can also use
setTimeOutlike this:setTimeout(function_name,2000);– Giovanni Perillo
Mar 23 '16 at 21:23
Correct, this is a slightly different variation of
setTimeoutthat 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