image
手动创建 image
创建一个 Image
对象:
var a = new Image();
定义 Image
对象的 src:
a.src=”xxx.gif”;
这样做就相当于给浏览器缓存了一张图片。
监听事件
var img = new Image();
img.onload = function () {
alert("img is loaded");
};
img.onerror = function () {
alert("error!");
};
img.src = "http://www.abaonet.com/img.gif";
function show() {
alert("body is loaded");
}
window.onload = show;
监听属性
img[src=""],
img:not([src]) {
opacity: 0;
} /*这样可以实现在路径为空时隐藏*/