我如何在fadeOut/fadeIn之前完成jQuery load()? [英] How can I get jQuery load() to complete before fadeOut/fadeIn?

查看:89
本文介绍了我如何在fadeOut/fadeIn之前完成jQuery load()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过jQuery load()进行AJAX调用,并且只返回一次,然后淡出旧内容并淡入新内容.我希望旧内容在显示新内容之前一直保持显示状态,这时将触发淡出/淡入.

I want to do an AJAX call via jQuery load() and only once it returns, then fadeOut the old content and fadeIn the new content. I want to old content to remain showing until the new content is retrieved, at which point the fade Out/In is triggered.

使用:

$('#data').fadeOut('slow').load('/url/').fadeIn('slow');

内容淡入和淡出,稍后load()调用返回,数据更新,但是淡入淡出已经完成.

the content fades in and out and a few moments the later the load() call returns, and the data updates, but the fade has already completed.

推荐答案

使用回调来控制调用的顺序.

Use callbacks to the control the order of the calls.

var $data = $('#data');
$data.fadeOut('slow', function() { 
    $data.load('/url/', function() { 
        $data.fadeIn('slow'); 
    }); 
});

(注意:我不确定100%是否使用 var $data = ... $data.doStuff() 是否可以正常工作-如果可以,它将保存您不必每次都在DOM树中查找div,但如果不是这样,则只需删除第一行并使用 $('#data') 无处不在...

这篇关于我如何在fadeOut/fadeIn之前完成jQuery load()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆