Free Advertising Forums | Free Advertising Board | Post Free Ads Forum | Free Advertising Forums Directory | Best Free Advertising Methods | Advertising Forums

Free Advertising Forums | Free Advertising Board | Post Free Ads Forum | Free Advertising Forums Directory | Best Free Advertising Methods | Advertising Forums (http://www.freeadvertisingzone.com/index.php)
-   Free Link Exchange (http://www.freeadvertisingzone.com/forumdisplay.php?f=65)
-   -   异步加载图片 (http://www.freeadvertisingzone.com/showthread.php?t=1121255)

04-28-2011 06:21 AM

异步加载图片
 
今天看到论坛上有人发了一个异步加载图片的后果,看了看主意确切不错,cheap ferragamo shoes,重要就是 树立一个$("<img \/>")对象,nike air max 2011,并动态设置它的src属性 在load停止的时候履行相应操作:
$('<img src="' + url + '">').load(function(){
$("#imgcon").html(this);
});
当然在涌现错误的时候咱们也能够用 如下方法来处置:
.error( //加载呈现毛病时
function(){
$("info").html(errorinfo);
}

)
综合这些,写了一个小例子:
$(function(){
var errorinfo="Error loading image"; //准备的过错信息
var tempimg=$('<img \/>'); //创立一个img对象
var loadinfo=$('<img src="http://nba.titan24.com/focus/kikx/trancepics/loadinfo.gif" class="loadinfo" />'); //加载提示图片
var li=$("#list li");
var imgcon=$("#large"); //图片容器
var url="http://nba.titan24.com/focus/kikx/trancepics/0.jpg"; //默认开端的图片
var loadnew=function loadnew(){ //加载显示图片的函数
tempimg
.attr("src",ghd iron,url) //设置地址
.load(function(){ //加载结束在相应地位显示
imgcon.html(this);
}).error(
function(){ //调取犯错报错
imgcon.html(errorinfo);
}
)
}
loadnew(); //初始化
li.mouseover(function(){
if(,tory burch private sale!$(this).hasClass("cur")){ //假如不是当前的
imgcon.html(loadinfo); //先显示加载提醒图片
url=$(this).find("a").attr("rel"); //获取要加载的图片地址
setTimeout(loadnew,300); //延时加载 避免鼠标疾速划过
cur(this,christian louboutin peep toe,"cur"); //标记当前
}
})
function cur(ele,currentClass){ //标志当前函数
ele= $(ele)? $(ele):ele;
ele.addClass(currentClass).siblings().removeClass( currentClass);
}

})

点击此处查看 DEMO


All times are GMT. The time now is 04:07 AM.

Powered by vBulletin Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Free Advertising Forums | Free Advertising Message Boards | Post Free Ads Forum