使用css自动重定向具有转换的页面

时间:2015-08-07 06:03:45

标签: html css redirect transition

当用户查看主页时,它会在5s后自动跳转到另一个页面。我想在跳转到另一个页面时添加淡入淡出过渡。有可能使用CSS吗?

这是我找到的编码,但转到另一页时没有转换。

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Vert Residence</title>
<link href="css/main.css" rel="stylesheet" type="text/css">


<meta name="language" content="en" />
<meta content='width=device-width, initial-scale=1.0' name='viewport' />
<!---<meta http-equiv="refresh" content="5;URL=vert-residence.html">--->

<link rel="stylesheet" href="css/jquery.maximage.css?v=1.2" type="text/css" media="screen" charset="utf-8" />
<link rel="stylesheet" href="../lib/css/screen.css?v=1.2" type="text/css" media="screen" charset="utf-8" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<style type="text/css">
.logo-index {
-webkit-animation-name: example;
/* Chrome, Safari, Opera */
-webkit-animation-duration: 5s;
/* Chrome, Safari, Opera */
animation-name: example;
animation-duration: 5s;
}


@-webkit-keyframes example {
0% {
opacity: 100;
filter: alpha(opacity=1000);
/* For IE8 and earlier */
}

100% {
opacity: 0.0;
filter: alpha(opacity=0);
/* For IE8 and earlier */
}
}


/* Standard syntax */
@keyframes example {
0% {
opacity: 100;
filter: alpha(opacity=1000);
/* For IE8 and earlier */
}

100% {
    opacity: 0.0;
    filter: alpha(opacity=0);
/* For IE8 and earlier */
}
}

</style>
</head>

<body>
<script>
setTimeout(function() {
  window.location.href = "aboutus.html";
}, 2000);
</script>



<div class="logo-index">
    <a href="aboutus.html"><img src="img/logo-index.png"></a>
</div>
</body>
</html>

当用户等待5秒时,它将自动转到aboutus.html

2 个答案:

答案 0 :(得分:0)

您必须进行一些调整,但您可以使用CSS过渡。你必须将它应用到你的整个页面并淡出一切。

html {
    -webkit-transition: all 1s ease-out;
    -moz-transition: all 1s ease-out;
    -o-transition: all 1s ease-out;
    -ms-transition: all 1s ease-out;
    transition: all 1s ease-out;
}

JSFiddle Example

答案 1 :(得分:0)

&#13;
&#13;
setTimeout(function() {
  window.location.href = "/NewPage.aspx";
}, 2000);
&#13;
.wrapper {


  background-color: red;


  width: 100%;


  -webkit-animation-name: example;


  /* Chrome, Safari, Opera */


  -webkit-animation-duration: 2s;


  /* Chrome, Safari, Opera */


  animation-name: example;


  animation-duration: 2s;


}


@-webkit-keyframes example {


  0% {


    opacity: 100;


    filter: alpha(opacity=1000);


    /* For IE8 and earlier */


  }


  100% {


    opacity: 0.0;


    filter: alpha(opacity=0);


    /* For IE8 and earlier */


  }


}


/* Standard syntax */


@keyframes example {


  0% {


    opacity: 100;


    filter: alpha(opacity=1000);


    /* For IE8 and earlier */


  }


  100% {


    opacity: 0.0;


    filter: alpha(opacity=0);


    /* For IE8 and earlier */


  }


}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class='wrapper'>
  <div>Home Page</div>
</div>
&#13;
&#13;
&#13;