Hey! When you say you'd like to add a timer or duration are you referring to the duration of the animation? Or using a timer to toggle every few seconds for example?
Write now it has a "click" function for toggle purposes. I would like to keep that the way it is, but also ad a timer of say 10 seconds to allow it to fade off with out the click
That seems to partially solve the issue. However, this bit of code causes the function to continuously cycle, instead of a occurring one time (which is how it should be)
Thanks for the reply. Still having some issues though. This bit of code simply determines the duration of the fade for the click function.
Let's say I have an image. With the current script if I click the image it fades away forever (which I want) — I would also like it to have a timer to fade away after say 10 seconds if it is not clicked immediately.
Also…I'm using Coda and was wondering if you know of any ways to merge multiple CSS (and JS) files into one of each? In addition I was also curious if Coda or any plugin for that matter is capable of 'minimizing' code itself.
I would suggest to place it after defining the click event for the DIV#test. What do you mean with merge JS & CSS? For minimizing JS is use http://javascriptcompressor.com/ and wrote my own CSS minimizer.
Sorry about that, so basically you want to add a loader div and then remove it after a set duration.
$(document).ready(function() {
// add loader div $('body').prepend('<div id="one"></div>').append('<div id="two"></div>');
// set timer for 10 seconds var bodyTmr = setTimeout(function() { clearTimeout(bodyTmr ); // fade out loader div and remove from page $('#one').fadeOut('fast').remove(); }, 10000); });
Just tested the following code below and it works as expected. Just made the #one div completely black instead of a loader image in the center. Maybe you are doing something in your js code?
// set timer for 10 seconds var bodyTmr = setTimeout(function () { clearTimeout(bodyTmr); // fade out loader div and remove from page $('#one').fadeOut('fast').remove(); }, 10000); }); </script> </head> <body> </body> </html>
I am trying to add a simple timer or duration to this snip of code, but not having much luck. I am rather new with JS so please excuse my ignorance.
Write now it has a "click" function for toggle purposes. I would like to keep that the way it is, but also ad a timer of say 10 seconds to allow it to fade off with out the click
That seems to partially solve the issue. However, this bit of code causes the function to continuously cycle, instead of a occurring one time (which is how it should be)
Thanks for the reply. Still having some issues though. This bit of code simply determines the duration of the fade for the click function.
Let's say I have an image. With the current script if I click the image it fades away forever (which I want) — I would also like it to have a timer to fade away after say 10 seconds if it is not clicked immediately.
thanks again
That's simple, this code below will only run once after 10 seconds. Hope it helps.
Nice! it worked. I just placed it before this portion
Is that correct? or should it go after?
Here is what I have as:
Thanks for your patience
Thank You
I would suggest to place it after defining the click event for the DIV#test. What do you mean with merge JS & CSS? For minimizing JS is use http://javascriptcompressor.com/ and wrote my own CSS minimizer.
For merging… Lets say I have 4 JS files and want to merge them into a single file instead of linking all 4
Similar to the timer question above,
looking at this bit of code here, I am trying to achieve the same result, however no click is needed. Just a timer.
No problem ask away. Regarding merging JS files:
1. Copy and paste all the scripts into a single JS file. lol
2. Load them dynamically with tools like 'RequireJS', 'LabJS', 'StealJS' or 'Bootstrap'.
Cons:
Having all the scripts in one file will make it hard to debug.
If i understand correctly you would like to append to the body after a couple of seconds?
the above code didnt seem to work for whatever reason
Here is my CSS also…
Just tested the following code below and it works as expected. Just made the #one div completely black instead of a loader image in the center. Maybe you are doing something in your js code?
I am wondering though, would it be more efficient to add the timer to this instead?
(to tell the id when to hide)