2

I'm trying to make a div disappear and reappear after a set amount of time.

Inside the div are div elements that fade in and fade out.

I thought this would work:

setTimeout(function() {
$( "#productDiv" ).removeAttr( "style" ).show().fadeIn();
}, 1000 );

but it isn't so I'm pretty sure I'm doing it wrong. I also can't figure out how to show the div again after a set time.

Can anyone take a look at this and give me pointers?

http://jsfiddle.net/linuxbastard/nGCNJ/5/

Thanks in advance.

  • Reffer to this link http://stackoverflow.com/questions/914951/show-and-hide-divs-at-a-specific-time-interval-using-jquery This would solve your problem. – Subhajit Jun 20 '12 at 07:17

2 Answers2

1

You can try this :- this will chain the effect after every 2secs

 $(document).ready(function(){
    setInterval(function() {
        $("#productDiv").show().delay(1000).fadeOut();
    }, 2000 );
 });
Subhajit
  • 1,929
  • 3
  • 19
  • 21
  • Hi Subhajit, that works! I should have used `setInterval` in the first place. LOL. [Finished code](http://jsfiddle.net/linuxbastard/nGCNJ/6/) – linuxbastard Jun 20 '12 at 07:57
0

Do it like this :

$("#productDiv").hide().delay(1000).fadeIn();

This hides the div, and program the fadeIn effect to be applied 1000 ms after that. That's the natural and idiomatic way to chain jquery effects.

Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
  • hi dystroy, I've done that before but as you indicated it starts the div hidden. reversing it with `$("productDiv").show().delay(1000).fadeOut();` starts it visible and then fades out, but don't know how to chain a timed fade in after that and loop it. – linuxbastard Jun 20 '12 at 07:26