<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>代理模式图片预加载</title>
</head>
<script src="js/jquery-3.1.0.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(function(){
var myImage = (function (){
var $imgNode = $('<img>');
$('body').append($imgNode);
return {
setImg:function(src){
$imgNode.attr('src',src);
}
};
})();
var proxyimg = (function(){
var img = new Image();
img.onload = function(){
myImage.setImg(this.src);
}
return {
setSrc:function(src){
myImage.setImg('img/1.gif');
img.src = src;
}
};
})();
var n = new proxyimg.setSrc('http://c.hiphotos.baidu.com/image/pic/item/6c224f4a20a44623bb32177f9a22720e0cf3d737.jpg');
});
</script>
</head>
<body>
</body>
</html>
})
</script>
<body>
</body>
</html>