开发者

ajax img change

开发者 https://www.devze.com 2023-01-18 08:10 出处:网络
i开发者_StackOverflow have implemented a code that fetch single image from 1000+ images. The image has been changed using ajax call and downloading time of each image varies. How to make this image ch

i开发者_StackOverflow have implemented a code that fetch single image from 1000+ images. The image has been changed using ajax call and downloading time of each image varies. How to make this image change with smooth transition from one another i.e without any flicker and ajax processing image


You could pre-select the images you are about to load and store it in a persistent array:

var image_paths = new Array();
/* fill image_paths */

window.preload_images = new Array();

for (var i in image_paths) {
    var image_src = image_paths[i];
    var img = new Image();
    img.src = image_src;
    preload_images.push(img);
}

This will tell the DOM to load the image into a JavaScript Image object but to not destroy it unless preload_images is unset.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号