这个问题在这里已有答案:
我试图创建一个功能,在一段时间后花在特定页面上,没有任何用户操作,它会将他重定向到另一个页面,但具有淡出效果。一切都很好,除了当前页面不淡出,只是简单地转到新页面。这是我的代码:
setTimeout(function(){
$('body').fadeOut('slow');
window.location.href = "index.html";
}, 6000);
fadeOut
方法接受另一个参数,该参数是动画完成时执行的callback
函数,因此,您可以在duration参数旁边传递包含重定向语句的函数:
setTimeout(function() {
$('body').fadeOut('slow', function() {
window.location.href = "index.html";
});
}, 6000);
希望我进一步推动你。
将位置更改放在fadeOut
完成后运行的回调中。
setTimeout(function(){
$('body').fadeOut('slow', function() {
window.location.href = "index.html";
});
}, 6000);
这可能会使你的setTimeout
多余。你可能只想要:
$('body').fadeOut('slow', function() {
window.location.href = "index.html";
});
你应该在文档或html部分使用fadeout():
$(document).fadeOut();
要么
$("html").fadeOut();
我希望这有帮助。