设置超时,淡出并转到url
setTimeout, fade out and go to url
我正在尝试创建一个功能,在特定页面上花费一段时间后,无需用户进行任何操作,它会将他重定向到另一个页面,但具有淡出效果。一切正常,除了当前页面不会淡出,只是简单地转到新页面。这是我的代码:
setTimeout(function(){
$('body').fadeOut('slow');
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();
希望对您有所帮助。
fadeOut
方法接受另一个参数,即动画完成时执行的 callback
函数,因此,除了持续时间参数外,您还可以传递一个包含重定向的函数声明:
setTimeout(function() {
$('body').fadeOut('slow', function() {
window.location.href = "index.html";
});
}, 6000);
希望我能把你推得更远。
我正在尝试创建一个功能,在特定页面上花费一段时间后,无需用户进行任何操作,它会将他重定向到另一个页面,但具有淡出效果。一切正常,除了当前页面不会淡出,只是简单地转到新页面。这是我的代码:
setTimeout(function(){
$('body').fadeOut('slow');
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();
希望对您有所帮助。
fadeOut
方法接受另一个参数,即动画完成时执行的 callback
函数,因此,除了持续时间参数外,您还可以传递一个包含重定向的函数声明:
setTimeout(function() {
$('body').fadeOut('slow', function() {
window.location.href = "index.html";
});
}, 6000);
希望我能把你推得更远。