jQuery淡出,加载,淡入 [英] jquery fadeout, load, fadein

查看:82
本文介绍了jQuery淡出,加载,淡入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JQuery,我想发生的事情是

I am using JQuery and what I want to happen is.

Div使用fadeOut命令淡出.然后,使用load命令从URL加载内容.然后,一旦加载了内容,它就会使用fadeIn命令淡入.

Div fades out using the fadeOut command. It then loads content from a url using the load command. Then once content loaded it fades back in using the fadeIn command.

我的代码是:

$("#myDiv").fadeOut().load('www.someurl.com').fadeIn()

但是,这不起作用.先闪烁,然后加载,然后加载.我认为问题是在加载完成之前就发生了褪色.

However this does not work. It kind of flashes then loads out then loads in. I think the problem is that the fading is happening before the load is complete.

我该怎么办

谢谢

推荐答案

,您可以使用 load()这样的回调函数:

you can use the load() callback function like this:

$("#myDiv").fadeOut().load("www.someurl.com", function(response, status, xhr) {
    $(this).fadeIn();
});

您可能想使用load()调用的状态来查看所有操作是否正确完成.

you might want to use the status of the load() call to see if everything was completed properly.

$("#myDiv").fadeOut().load("www.someurl.com", function(response, status, xhr) {
    if (status == "error") {
        // handle error
    }
    else
    {
        $(this).fadeIn();
    }
});

这篇关于jQuery淡出,加载,淡入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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