我试图控制jquery中函数的顺序,点击id就像淡出图像一样,要交换图像的源,然后新图像淡入。
我有以下此类作品,只是它同时完成所有这些工作,他们是防止这种情况的方法吗?
// Animate height of div containing information
$(this).animate({
'height' : '600px'
},500, function(){
$('html, body').animate({ scrollTop: $(this).offset().top });
// Fade initial image out
img.fadeOut();
// Switch to hi-red image
img.attr('src', function(i, value) {
return '_includes/images/work/hires/' + value;
});
//Fade Hi res image in
img.fadeIn();
});
最佳答案
fadeOut
可以采用 complete
属性:http://api.jquery.com/fadeOut/
// Animate height of div containing information
$(this).animate({
'height' : '600px'
},500, function(){
$('html, body').animate({ scrollTop: $(this).offset().top });
// Fade initial image out
img.fadeOut(400, function() {
// Switch to hi-red image
img.attr('src', function(i, value) {
return '_includes/images/work/hires/' + value;
});
//Fade Hi res image in
img.fadeIn();
});
});
关于javascript - 排序 jQuery 函数,仅在最后一个完成时运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14460288/