three small absolutely positioned divs in my homepage

I have three small absolutely positioned divs in my homepage. i want only one div to appear at a time, so that the page should start with only the first div and after 3 seconds, the second div and after 3 seconds the third div and this process should continue infinitely. this is the for-loop I've come up with for doing this 10 times. how can i make the same happen infinitely?

// this for not making infinite loop
var nb_loop=0;
var max_loop=10; 
var j=0;
for (var i=2; i<=3 ; i++){
  nb_loop++;
  j++;
  console.log("i="+i+", j="+j); // or alert if you want
  if (j>=3)
    j=0;
  if (i>=3)
    i=0;
  if (nb_loop>max_loop)
    break; 
}

Answers


JS:

var counter = 1;
function showDiv(){
$('.display').hide();
$('#div'+counter).show();
(counter == 4 ? counter = 1 : counter++)
}

showDiv();
var timer = setInterval(showDiv, 3000);

HTML:

 <div id='container'>
   <div id='div1' class='display' style="background-color: red;"> 
        div1
   </div>

    <div id='div2' class='display' style="background-color: green;"> 
       div2
    </div>

    <div id='div3' class='display' style="background-color: blue;"> 
       div3
    </div>

     <div id='div4' class='display' style="background-color: yellow;"> 
       div4
     </div>
 </div>

CSS:

 .display { display: none; }

Use Jquery setInterval function use for infinite time


use JQUERY SETTIMEOUT() function

like this

 jQuery(document).ready(function () {
    //hide a div after 3 seconds
   setTimeout(function(){ jQuery("#div").hide(); }, 3000);

 });

Need Your Help

Error trying to access native method

blackberry blackberry-simulator blackberry-jde native-methods

Am developing a BlackBerry app and I have a third party JAR file which i make it as library and i am extending it in my application.

How to configure a netty pipeline for a http proxy

java http netty http-proxy

I wrote a small http proxy using Netty and it has worked fine for some time now. Today I began getting strange exceptions in the log file coming from a single client: