I have three background images, but because the x and y axes have to be tiled, I can’t use css sprites. However, I want these three background images to be displayed at the same time, either not displayed or displayed at the same time. So I want to load these three images first and then start css rendering. How can this be done?
Thank you everyone ~
<!DOCTYPE HTML><html> <head> <meta charset="gb2312" /> <title></title> </head> <body> <div id="test" style="width:120px; height:120px;"></div> <script> function $(el){ return typeof el == 'string' ? document.getElementById(el) : el; } var img = new Image; img.src = 'http://avatar.profile.csdn.net/D/2/3/2_yiqiejieruying.jpg'; img.onload = function(){ $('test').style.backgroundImage = 'url('+img.src+')'; } </script> </body></html>
HTML code
> ">