I have a snippet to make my page refresh every minute. However, I want the page to fade out to a specific color, then refresh and fade in again. Any easy way to do that?
This is the code I use;
setInterval("refresh();",60000);
function refresh(){
window.location = location.href;
}
I found this code while searching for a solution, but unsure on how I can use this in a interval;
$("body").fadeOut(
function(){
location.reload(true);
$( document).ready( function(){$(body).fadeIn();});
});
I have a snippet to make my page refresh every minute. However, I want the page to fade out to a specific color, then refresh and fade in again. Any easy way to do that?
This is the code I use;
setInterval("refresh();",60000);
function refresh(){
window.location = location.href;
}
I found this code while searching for a solution, but unsure on how I can use this in a interval;
$("body").fadeOut(
function(){
location.reload(true);
$( document).ready( function(){$(body).fadeIn();});
});
Share
Improve this question
edited Aug 19, 2015 at 12:23
Popnoodles
28.4k3 gold badges48 silver badges55 bronze badges
asked Aug 19, 2015 at 11:51
zorensenzorensen
3344 silver badges19 bronze badges
2 Answers
Reset to default 5DEMO
Add this CSS to hide body on page load.
body{display:none};
Then on load, fade body in.
After 60 seconds fade it out, then trigger page reload by putting it inside the callback that executes after fadeOut finishes.
$(function(){
$('body').fadeIn(1000);
setTimeout(function(){
$('body').fadeOut(1000, function(){
location.reload(true);
});
}, 60000);
});
No need to use setInterval as the page gets reloaded; setTimeout is fine.
You need to do it in a different way:
.hidden {display: none;}
$(document).ready(function () {
$("body").removeClass("hidden").hide().fadeIn(400);
});
I am not sure how to do it while unloading page. Might not work always.