@{ ViewBag.Title = "imageonload"; Layout = null; } <!DOCTYPE html> <html> <head> <title>图片预加载</title> <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script> <script language="javascript" type="text/javascript"> jQuery(document).ready(function () { jQuery("#sanma img").each(function () { var thisimg = jQuery(this); thisimg.attr("src", "/css/load.gif"); thisimg.load(function () { var types = thisimg.attr("realsrc"); thisimg.attr("src", types); }); }); }); </script> </head> <body> <div id="sanma"><img id="beifeng" src="http://www.xdjd.cn/video/pic/20130528094538xdjd53199.jpg" realsrc="http://www.xdjd.cn/video/pic/20130528094538xdjd53199.jpg" height="200px" width="150px"/></div> </body> </html>
问题是,ie下load图片不出来,空白一会才显示原图,大家看下,谢了!
ie的处理速度是没有火狐等现代浏览器快,出现这种情况很正常,thisimg.attr("src", "/css/load.gif");就没必要写,直接在
<div id="sanma"><img id="beifeng" src="/css/load.gif" realsrc="http://www.xdjd.cn/video/pic/20130528094538xdjd53199.jpg" height="200px" width="150px"/></div>