我想在我的光滑滑块上加载所有图像时立即显示图像, 但它不起作用。
var myPhotos = {
_counter: 0,
images: [],
init: function() {
ServerCall1(0, 'xml', 'rssphotos.php', function(xml) {
imageObj = new Image();
$(xml).find('item').each(function() {
var desc = $(this).find('description').text();
var resp = getImgArray(desc);
myPhotos.images[myPhotos._counter] = resp[0];
myPhotos._counter++;
});
//start preloading
for (i = 0; i < myPhotos._counter; i++) {
imageObj.src = myPhotos.images[i];
}
////PUT THE HEADER HOME PAGE
topHeader.putData(topHeader.photoData());
});
}
};
执行此函数后,我循环遍历myPhotos.images
以立即获取它们,但它的渲染速度非常慢。
答案 0 :(得分:1)
也许这个
var myPhotos = {
_counter: 0,
images: [],
init: function() {
ServerCall1(0, 'xml', 'rssphotos.php', function(xml) {
$(xml).find('item').each(function() {
var desc = $(this).find('description').text();
var resp = getImgArray(desc);
myPhotos.images[myPhotos._counter] = resp[0];
myPhotos._counter++;
});
//start preloading
for (i = 0; i < myPhotos._counter; i++) {
this.images[i]= new Image(); this.images[i].src = myPhotos.images[i];
}
////PUT THE HEADER HOME PAGE
topHeader.putData(topHeader.photoData());
});
}
};