我可以将.load函数与jQuery中的fadeIn结合使用吗? [英] Can I combine the .load function with fadeIn in jQuery?

查看:65
本文介绍了我可以将.load函数与jQuery中的fadeIn结合使用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用.load函数使用jQuery加载另一个页面.

I am using the .load function to load in another page using jQuery.

这是我的代码:

$('#page1').click(function(){                           
  $("#content").load("page1.html");
});

效果很好,但是我想在新页面中淡出.无论如何,我可以结合使用load和fadeIn函数吗?我尝试过,但是没有用.

It's working great, but I would like to fade in the new page. Is there anyway I can combine the load and fadeIn function? I attempted it, but it's not working.

这是我的尝试:

$('#page1').click(function(){                           
  $("#content").load("page1.html").fadeIn("normal");
});

如何结合.load和.fadeIn函数?

How can I combine the .load and .fadeIn function?

推荐答案

load的调用将使用AJAX,并且将异步运行.您需要在通话结束后立即淡入.您可以通过传递要加载的回调来实现.您的代码将如下所示:

The call to load will use AJAX and will be run asynchronously. You'll want to fade in right after the call is terminated. You can achieve that by passing a callback to load. Your code will look like this:

$('#content').load("page1.html", {}, function() { $(this).fadeIn("normal"); }));

有关更多信息,请参见有关jQuery的.load()的文档.

See documentation on jQuery's .load() for more information.

这篇关于我可以将.load函数与jQuery中的fadeIn结合使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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