开发者

jQuery AJAX GIF preloader for CSS Background-Image

开发者 https://www.devze.com 2023-02-09 19:30 出处:网络
I\'ve been using jQuery AJAX preloadin开发者_Go百科g GIF images for a while now, by this code: $(\"#images\").html(\"<img id=\'loader\' src=\'../img/ajax-loader.gif\' />\");

I've been using jQuery AJAX preloadin开发者_Go百科g GIF images for a while now, by this code:

$("#images").html("<img id='loader' src='../img/ajax-loader.gif' />");

What i'm trying to do now is, how can i implement this same effect (a spinning wheel or similar) to preload CSS background images not just img tags?

Is this possible?


Once the browser has loaded an image into cache, it can retrieve it from cache for img tags or for css backgrounds. So I believe if you continue doing exactly what you are doing to preload images, then you can use that to preload background images. In other words, if you have this css:

#SomeElement { background: url('../img/whatever.gif'); }

then you can do this to preload it:

$("#images").html("<img id='loader' src='../img/whatever.gif' />");

I am not entirely familiar with your technique for preloading however, so I could be wrong...


for img tag, obviously you can capture onload event, but when you are dealing with css background images, I don't think and never heard capture the onload event for css background image.

0

精彩评论

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

关注公众号