Monday 15 February 2010

for Loop not working in javascript? -


When I open it in the browser, the previous image will show why the loop is not working?

  Var i = 0; Function set () {for (i = 1; i & lt; = 5; i ++) {var image = "& lt; img src = images / sl" + i + ".jpg" + "width = '500 'Height =' 300 'style =' margin-left: 400 pixels; '/ ";"; "; Document.getElementById ("Slider"). InnerHTML = Image; }} SetInterval ("set ()", "600"); & Lt; Div id = "slider" & gt; & Lt; Img src = "picture / SL1.jpg" /> & Lt; / Div & gt;   

I am creating a simple slider in javascript but when I run it only shows me the previous image from my images folder like i have 5 images sl1. Sl2 | ... sl5 ... only my previous image 5 ... loop is not working ..

Maybe this is what you want?

  function set image (i) {var image = "& lt; img src = images / sl" + i + ".jpg" + "width = '500' height = '300' Style = 'margin-left: 400 pixels;' / ";"; "; Document.getElementById ("Slider"). InnerHTML = Image; } Function loopImages (i) {setImage (i); // Set the current image if (i == 5) {i = 1; // set counter) setout (function () {loop images (i ++);}, "600"); Set next image in // 600 MSI loopImages (1);   

Do not know if you want to stop that image 5 or the rope forever

No comments:

Post a Comment