2

I tried implementing it.But..the image changes from the first to the secnd and then stops.

for your reference,please find the code i tried to implemented.

<div id="images"> <img  name="slide" src="img/banner1.png"/>
<script type="text/javascript" >
var slideShow=document.getElementById("images");
var allImages= new Array();
allImages=["img/banner3.png","img/banner2.png","img/banner4.png","img/banner5.png"];
var imageIndex=0;
function changeImage()
{
    document.images.slide.src=allImages[imageIndex];
    //slideShow.setAtrribute("src",allImages[imageIndex]);
    console.log("executing 1");
    imageIndex++;
    if(imageIndex >= allImages.length)
    {
       console.log("executing 2");
       imageIndex=0;
    }
}console.log("executing 3");
setTimeout("changeImage()",1000);
console.log("executing 4");
</script>
</div>

Can Someone,help me in fixing this issue..Please!

7
  • Please make a JsFiddle File with some images..I will rectify your problem..!! Commented May 17, 2013 at 5:32
  • Can you create a fiddle Commented May 17, 2013 at 5:34
  • Click here for a reference. Commented May 17, 2013 at 5:41
  • @ Kishor Subedi,@Sree ram---check this Pardon me..if any mistake..this was my first work on Jsfiddle Commented May 17, 2013 at 5:43
  • Yeah that's empty. Save it, then copy the link. Commented May 17, 2013 at 5:45

2 Answers 2

2

This is the similar script you are searching for...

Java Script

slide=new Array("images/2.jpg","images/3.jpg","images/4.jpg","images/5.jpg","images/6.jpg","images/8.jpg")
pic=0;

function start()
{
setInterval("fun()",3000);
}

function fun()
{
document.show.src=slide[pic];
pic++;
if(pic==6)
pic=0;
}

HTML

<body onLoad="start();>
-------
-------
</body>
Sign up to request clarification or add additional context in comments.

Comments

1

If you want to make the infinite slide show use setInterval instead of setTimeout.

setInterval('changeImage()',1000);

Your code works as fine after changing it. Enjoy.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.