views:

897

answers:

2

I have been trying to make a div fade in evey 30sec and out after 30sec

setInterval(function(){$('#myDiv').toggle();}, 300);
$("#popupboxdis").fadeIn("fast");
$("#popupboxdis").fadeOut("fast");
+3  A: 

The setInterval time is in milliseconds:

setInterval(function(){
    $('#myDiv').toggle('normal');
}, 30000);

Notice the extra 0s. As it is right now it will try to toggle the element every 300 milliseconds or .3 seconds which is probably resulting in some wacky behavior. Also, the code above should do what you described, I am not sure where the other 2 lines come into play...

Also note that without a time string ('slow', 'normal', 'fast') or a time in ms (1000, 2000) as an argument, toggle will simply hide and show the elements without the fading animation you are looking for.

Paolo Bergantino
A: 

I guess you are trying to toggle between fadeOut and fadeIn.

setInterval(function() {
    $('#myDiv').toggle(function() {
        $(this).fadeOut('fast');
    }, function() {
        $(this).fadeIn('fast');
    });
}, 30000);
Artem Barger
toggle('fast') achieves this... why complicate it?
Paolo Bergantino
toggle("fast") iterates between show/hide and not fideIn/fideOut
Artem Barger
Depends on the effect you're looking for. Toggle chooses how to fade in / fade out. fadeIn/fadeOut has more control.
ScottE
Yeah, ScottE, I see that. toggle('fast') seems to do a slideDown/fade mix, which is odd.
Paolo Bergantino