如何验证背景(css)图像加载? [英] How to verify background (css) image was loaded?
本文介绍了如何验证背景(css)图像加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下CSS类
.bg {
background-image:url('bg.jpg ');
display:none;
}
我在TD标签上申请。
我的问题是我怎么能告诉JavaScript / jQuery的背景图片完成加载?
谢谢。 b
$ b
UPDATE:添加的显示属性。
因为我的主要目标,它切换到视图。
解决方案
我知道这样做的唯一方法是使用Javascript加载图片,然后将该图片设置为背景。
例如:
var bgImg = new Image();
bgImg.onload = function(){
myDiv.style.backgroundImage ='url('+ bgImg.src +')';
};
bgImg.src = imageLocation;
I have the following CSS class
.bg {
background-image: url('bg.jpg');
display: none;
}
that I'm applying on a TD tag.
My question is how can I tell with JavaScript/jQuery that the background image finished loading?
Thank you.
UPDATE: added display property. Since my main objective it toggle it into view.
解决方案
The only way I know of to do this is to load the image using Javascript, and then set that image as the backgroud.
For example:
var bgImg = new Image();
bgImg.onload = function(){
myDiv.style.backgroundImage = 'url(' + bgImg.src + ')';
};
bgImg.src = imageLocation;
这篇关于如何验证背景(css)图像加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文