在jquery中做效果后转到链接
我想淡出当前页面并淡入新页面。淡入效果很好,但是当我尝试在单击链接时淡出 div 时,它只会加载新页面,但不会先淡出。我想要淡出和内容中的 div 加载了这样的 php 函数:
Script:
<script type="text/javascript">
$(function(){
$('#article').fadeIn('250');
$('a').click(function() {$('#article').fadeOut('250')});
});
</script>
Link:
<a href="index.php?n=1"><li>Article 1</li></a>
Div:
<div id="article">
<?php
$n='articles/article'.$_GET['n'].'.php';
if (is_file($n)) {include($n);} else {include ("articles/error.php");}
?>
</div>
编辑:
我已经通过混合你的答案来完成它,但我有一个问题,淡出的持续时间效果不起作用。无论我使用多长时间,它总是需要相同的时间。这就是我现在所拥有的:
<script type="text/javascript">
$(function () {
$('a').click(function () { var a = $(this);
$('#article').fadeOut( 250, function () { window.location = 'index.php?n=' + a.attr('rel'); }); return false; });
$('#article').hide().fadeIn(250);
});
</script>
I want to fade out the current page and fade in the new one. The fade in work well, but when I try to fade out the div when the link is clicked, It just load the new page, but it doesn't fade out first. The div's which I want to fade out and in content is a loaded with a php function like this:
Script:
<script type="text/javascript">
$(function(){
$('#article').fadeIn('250');
$('a').click(function() {$('#article').fadeOut('250')});
});
</script>
Link:
<a href="index.php?n=1"><li>Article 1</li></a>
Div:
<div id="article">
<?php
$n='articles/article'.$_GET['n'].'.php';
if (is_file($n)) {include($n);} else {include ("articles/error.php");}
?>
</div>
EDIT:
I have already done it by mixing your answers, but I have a problem, the duration of the fadeOut effect doesn't work. No matter what duration I use, it always takes the same. That's what I have now:
<script type="text/javascript">
$(function () {
$('a').click(function () { var a = $(this);
$('#article').fadeOut( 250, function () { window.location = 'index.php?n=' + a.attr('rel'); }); return false; });
$('#article').hide().fadeIn(250);
});
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
返回 false 以阻止导航。动画完成后使用回调来手动导航。
Return false to prevent navigation. Use callback after animation completes to navigate manually.
您的链接正在按照预期进行重定向。
像这样改革你的 html 链接:
并像这样改革你的 jQuery:
Your link is redirecting as it is supposed to.
Reform your html Link like this:
and reform your jQuery like so:
尝试在 fadeOut 函数调用中使用回调。
Try using a callback in the fadeOut function call.
不需要每次刷新整个页面,只需将新内容加载到文章 div 中即可,如下所示:
链接:
脚本:
There is no need to refresh the entire page each time, just load the new content into the article div like so:
link:
Script: