我可以在 jQuery 中将 .load 函数与 fadeIn 结合起来吗?

发布于 2024-08-12 09:50:50 字数 436 浏览 1 评论 0原文

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

这是我的代码:

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

它工作得很好,但我想淡入新页面。无论如何,我可以将 load 和 fadeIn 功能结合起来吗?我尝试过,但它不起作用。

这是我的尝试:

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

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

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

Here is my code:

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

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.

Here is my attempt:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

恬淡成诗 2024-08-19 09:50:50

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

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

有关详细信息,请参阅有关 jQuery 的 .load() 的文档

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"); }));

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

汹涌人海 2024-08-19 09:50:50

加载前隐藏#content,加载完成后淡入整个div。我猜想 load 接受回调函数......?

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

编辑按照米格尔说的去做,无论如何=)

Hide #content before the load, and fade in the entire div when load is complete. I'd guess load acceps a callback function...?

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

EDIT do what miguel said, anyway =)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文