javascript - 排序 jQuery 函数,仅在最后一个完成时运行

标签 javascript jquery

我试图控制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/

相关文章:

javascript - 我无法找出这个 jQuery 中的错误

jquery - jqm+phonegap 中的 pagebeforeshow 事件有问题吗?

jquery - 如何使用 javascript 将哈希标签替换为 jquery 数据属性中的链接

javascript - 使用 Redux-Router + React-Router 将基本 URL 添加到应用程序

javascript - 在 foreach 循环内将输入文本复制到另一个文本?

javascript - 从 GTM 访问数据层

javascript - HTML 大小调整问题

javascript - 如何在另一个 div 可见时隐藏它?

Javascript - 替换字符串中的一定数量的字符并保留其余字符

javascript - Bootstrap Switch 触发 switchChange 事件但视觉上没有变化