0

This is the Js Fiddler of the question because until it's run i don't see how this could possibly make sense. Loop of img src and i loop through them and place them in an img.src and load them and then append to an element. I have tried various other methods that just seems to not work and i have no idea why this would happen. Is it a problem with jsfiddler or is my code incorrect?

http://jsfiddle.net/shavyg2/GsQtn/embedded/result/

    /*Slide show*/
var container=$(".imageContainer");

var imageList=["http://blogs.adobe.com/captivate/files/2011/09/HTML5.jpg",               "http://www.hanselman.com/blog/content/binary/Windows-Live-Writer/HTML5-Support-for-Visual-Studio-2010---W_90C5/vshtml5_2.png",              "http://photos4.meetupstatic.com/photos/event/d/e/0/0/event_117656832.jpeg",               "http://e4dhtml5.azurewebsites.net/Content/html5man.jpg",               "http://la-matrice.org/wp-content/uploads/2013/02/css3.png"];

var count=0;
for(var i=0;i<imageList.length;i++){
    var image=new Image();
    var number=i+0;
    image.src=imageList[number];
    container.append(image);    
    container.append(imageList[number]);
    image.load();
    count++;
}

container.append(count);
1
  • the reason for the +0 is that i wanted to make sure it wasn't a reference of i being saved but the actual value of the expression. it didn't help either way. that was the same reason i did number as a new var as well. with or without it still didn't work; Commented May 26, 2013 at 17:14

4 Answers 4

1

Remove image.load() in your for loop.

for(var i=0;i<imageList.length;i++){
    var image=new Image();
    var number=i+0;
    image.src=imageList[number];
    container.append(image);    
    container.append(imageList[number]);
    count++;
}

http://jsfiddle.net/6skav/

Get rid of "container.append(imageList[number]);" if you don't want the url to display.

Sign up to request clarification or add additional context in comments.

Comments

1

http://jsfiddle.net/GsQtn/1/

This seems to do what you are intending. I think the problem is with all your extraneous image code. Basically the loop that I implemented looks like this:

for(var i=0;i<imageList.length;i++){
    var image = document.createElement("img");
    image.src=imageList[i];
    container.append(image);
    count++;
}

1 Comment

i figured it out. i didn't need to call load function like i do with audio and video tags
1

I tried this in the fiddle and it worked.

for(var i=0;i<imageList.length;i++){
   var image=new Image();
   image.src=imageList[i];
  container.append(image);    
}

enter image description here

2 Comments

hmm maybe my screen was small.. let me check again
those are the pictures. it just doesn't work on my screen i have no idea why
0

The reason this wasn't working was that I was calling the image.load() function. I got use to working with audio and video tags which recently i was doing, you don't need to call load for images. In fact it doesn't have that method.

this is the final working code with out the testing stuff

  for(var i=0;i<imageList.length;i++){
    var image=new Image();
    image.src=imageList[i];
    container.append(image);    
    }

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.