[英]FadeIn an Image after being fully loaded after ajax request
我的主要目的是將相當大的圖像加載到我的#pictureframe div中,並在加載的圖像中淡入淡出。
以下代碼可以正常工作,但是問題是正在加載的圖像沒有像預期的那樣褪色。
我的html頁面是
<div id="picture">
<div id="pictureframe">
</div>
</div>
另外我的Java腳本功能如下
$('#content').on('click',".lstimages .imgthumb",(function(){
var photoid = $(this).attr('alt');
$.ajax({
dataType: "json",
url: '/ajax/pictureview/load/' + photoid,
success: loadImg
,
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
}));
function loadImg(data)
{
$('#picture > #pictureframe').hide().html("<img alt='"+ data[0].pictureid +"' src='"+ data[0].filepath + "'>").fadeIn();
}
如果找到答案
$('#picture > #pictureframe').hide().html("<img alt='"+ data[0].pictureid +"' src='"+ data[0].filepath + "'>");
$('#picture > #pictureframe img').bind("load", function() {
$('#picture > #pictureframe').fadeIn();
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.