如何使用 delay() 使用 $.each() 遍历 JSON?
我希望每个图像使用fadeIn() 和fadeOut() 显示3 秒。
JSFiddle:http: //jsfiddle.net/8x6rR/23/
// JSON source
var sponzorji = [{
logo: "http://dijaki.gimvic.org/2a/stara/miha/javascript/slider/img/interspar.png",
link: "http://www.center-vic.si/",
naziv: "Interspar Vič"
}, {
logo: "http://dijaki.gimvic.org/2a/stara/miha/javascript/slider/img/plesna_sola_urska.png",
link: "http://www.urska.si/",
naziv: "Plesna Šola Urška"
}, {
logo: "http://dijaki.gimvic.org/2a/stara/miha/javascript/slider/img/sae.png",
link: "http://ljubljana.sae.edu/sl/home/",
naziv: "SAE Ljubljana"
}];
// HTML
var linkEl = $("a#link"),
imgEl = $("img#slika");
// mainLoop
function mainLoop() {
$(sponzorji).each(function (index) {
linkEl.attr("href", this.link).find(imgEl).attr({
src: this.logo,
alt: this.naziv
});
// Recursive
if (index == sponzorji.length - 1) {
mainLoop();
}
});
} // end mainLoop
mainLoop();
谢谢!