最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery: Refresh page with fadein and fadeout - Stack Overflow

programmeradmin4浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 5

DEMO

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.

发布评论

评论列表(0)

  1. 暂无评论