jQuery 淡入淡出效果以转移到另一个页面

jQuery fadein effect to transfer to another page

本文关键字:另一个 转移 淡入 淡出 jQuery      更新时间:2023-09-26

我正在尝试设置加载页面,并在移动到索引.html页面之前将超时设置为 5 秒。我想通过一些基本的过渡淡入淡出转移到此页面,我想知道我该怎么做?

我目前的代码是:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title> Go Post - HomePage </title>
        <link rel="stylesheet" href="includes/style.css">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script>
            setTimeout(function(){
                window.location='index.html';
            }, 3000);
        </script>
    </head>
    <body>
        <div class="load"></div>
    </body>
</html>

你可以简单地通过jquery fadeOut来做到这一点。

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title> Go Post - HomePage </title>
        <link rel="stylesheet" href="includes/style.css">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <!-- Import jquery -->
        <script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
        <script>
            setTimeout(function(){
                $('html').fadeOut(
                    500,  // animation time
                    function(){
                        // action will do after the animation
                        window.location='index.html';  
                    }
                );
            }, 3000);
        </script>
    </head>
    <body>
        <div class="load"></div>
    </body>
</html>

试试下面

在 HTML 中添加div

<div id="preloader">
</div>

jQuery

$(function() {
  setTimeout(function() {
    $('#preloader').fadeOut('slow', function() {
      window.location = "https://google.com";
    });
  }, 5000);
});

.CSS:

div#preloader {
  background: url("http://www.mytreedb.com/uploads/mytreedb/loader/ajax_loader_blue_512.gif") no-repeat scroll center center #000000;
  height: 100%;
  position: fixed;
  width: 100%;
  z-index: 999;
}

演示 : http://codepen.io/anon/pen/gPqLPX