[英]jquery how to fade out and fade in images when changing attr src with json
I am stuck as to how fade in and out images when changing the attr src using jquery and json. 当使用jquery和json更改attr src时,我被困在如何淡入和淡出图像。 I have got the image changing correctly but would like to add the fading transition.
我已正确更改图像,但想添加淡入淡出过渡。
Any help and suggestions would be very appreciated. 任何帮助和建议将非常感激。
Below is my code 以下是我的代码
function(){
$j(".screenshots ul li#screen1").show();
$j(".items div a").click(function (event) {
var id = $j(this).attr("href");
//$j(".screenshots ul li img").fadeOut();
$j.ajax({
url: "/?func=square_images/get_json&IMAGE_ID="+id,
dataType: "json",
success: function(data) {
$j("#screen1 img").attr("src", data.medium_medium_src);
}
});
event.preventDefault();
});
}
You can try this within you success function 您可以在成功功能中尝试这一点
success: function(data) {
$j("#screen1 img").fadeOut(100, function() {
$(this).attr('src', data.medium_medium_src).load(function() {
$(this).fadeIn();
});
})
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.