Reputation: 1432
Is there a general issue with JQuery or something more specific that is preventing this from working properly in IE? This Fiddle is a fork.
http://jsfiddle.net/AndyMP/bYrdk/
var images = [
"http://imaging.nikon.com/lineup/dslr/d90/img/sample/pic_003t.jpg",
"http://imaging.nikon.com/lineup/dslr/d90/img/sample/pic_005t.jpg",
"http://imaging.nikon.com/lineup/dslr/d90/img/sample/pic_001t.jpg"
];
var delay = 2000;
var transition = 1000;
for(var i in images)
{
var img = document.createElement("img");
img.src = images[i];
img.onload = function(){
var parent = document.getElementById("content");
parent.insertBefore(this,parent.childNodes[0]);
if(i == images.length - 1)
{
i = 0;
startSlides();
}
}
}
function startSlides()
{
$("#content img:last").delay(delay).fadeTo(transition,0,function(){
$(this).insertBefore($(this).siblings(":first")).fadeTo(0,1);
startSlides();
});
}
Upvotes: 0
Views: 182
Reputation: 117334
The div is empty, so it doesn't have any childNodes and the argument parent.childNodes[0]
provided to insertBefore() causes an error, because insertBefore()
expects a node(and get's an 'undefined')
Insert at least a
into the div or use jQuery:
$(this).prependTo(parent);
Upvotes: 1
Reputation: 324650
Most likely problem is that you are using a for..in
loop to iterate an array. NEVER do this, because you will get elements from the array's prototype and all the way back up to the Object.
Next, you are not using Closures correctly. By the time the image loads, the value of i
will have changed, and will be equal to images.length
(assuming you weren't screwed over by the first problem. Create a new Closure where the value of i
is anchored:
img.onload = (function(i) {return function() {
var parent = .........................
};})(i);
These problems are not caused by jQuery, but by your misunderstanding of basic JavaScript.
Upvotes: 2