1
I have the following code I’d like you to do fadeIn
and fadeOut
after 3 seconds. I thought to use setInterval
to loop and then use a setTimeout
to give the time that each div
was visible. Is there any way to do what I wish? I have something wrong in my code?
setInterval(function(){
setTimeout(function(){
$(".emer3").fadeOut("fast");
$(".emer1").fadeIn("fast");
}, 3000);
setTimeout(function(){
$(".emer1").fadeOut("fast");
$(".emer2").fadeIn("fast");
}, 3000);
setTimeout(function(){
$(".emer2").fadeOut("fast");
$(".emer3").fadeIn("fast");
}, 3000);
}, 9000);
<div class="col-lg-12 col-sm-12 col-xs-12 col-md-12" style="margin-top:100px;">
<div class="col-lg-4 col-sm-4 col-xs-4 col-md-4 emer1">
252 252 252
</div>
<div class="col-lg-4 col-sm-4 col-xs-4 col-md-4 emer2" style="display:none">
252 252 252
</div>
<div class="col-lg-4 col-sm-4 col-xs-4 col-md-4 emer3" style="display:none">
252 252 252
</div>
</div>
Example in this JSFIDDLE
But what’s the problem with this code? It’s working, if that’s not the effect, it explains a little better, it got a little confused what you want to do.
– AnthraxisBR
@Anthraxisbr https://jsfiddle.net/nek7xugw/1/ See an example here
– I_like_trains
What is the idea of
setInterval
? You want to hide it again later?– Sergio
@Sergio O
setInterval
is supposed to function as an infinite Lopp but is not working as expected– I_like_trains
But you want to show and then hide? SetTimeout runs 1 time, and why do you want to run it again?
– Sergio
Because they are different Ivs, each with a class, and with these setTimeout defines the time that each one gets.
– I_like_trains
You want to blink a wink?
– HudsonPH
@Hudsonph No, I want the div to appear, hold for 3 seconds, disappear and appear the next
– I_like_trains
jquery Fades support complete callbacks to chain animations. That’s what you want to do?
– Isac
@Isac I didn’t quite understand what you said
– I_like_trains
I’m asking if the idea was for the 3 setTimeouts to run one at a time in sequence? Or if the 3 at the same time?
– Isac
@Isac Sequência
– I_like_trains