qadenza
qadenza

Reputation: 9293

setInterval calling function having setTimeOut

Initially moto is hidden 10s;
After 10s it should be visible.
Stay visible - 15 sec.
Hide

and again:
- hidden 10s...

Here si my try, without success - moto is never shown.

function go_anima(){
	$("#moto").hide();
	setTimeout(function(){$("#moto").fadeIn();}, 10000);
}

   $(document).on('ready', function(){
	setInterval(function(){go_anima();}, 25000);
});
.moto{display:none;}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class='moto' id='moto'>LOREM IPSUM</div>

Upvotes: 1

Views: 62

Answers (1)

trincot
trincot

Reputation: 350137

There is no "ready" event1 emitted by the document:

 $(document).on('ready', function(){

Instead you need the ready method:

 $(document).ready(function(){

Or, preferred, just:

 $(function(){


1The "ready" event was available in older jQuery versions, as stated in the documentation:

There is also $(document).on( "ready", handler ), deprecated as of jQuery 1.8 and removed in jQuery 3.0.

Upvotes: 4

Related Questions