如何使用javascript在设定的秒数 - 2秒后加载页面

时间:2017-06-20 10:19:27

标签: javascript html css dom

我正在尝试通过使用javascript操作DOM来创建一个页面在2秒后加载的效果

我怎样才能做到这一点?

3 个答案:

答案 0 :(得分:0)

<script>setTimeout(function(){window.location.href='page.html'},5000);</script>

仅限索引页面使用&#39; /&#39;

<script>setTimeout(function(){window.location.href="/"},3000);</script>

答案 1 :(得分:0)

创建绝对定位元素,2秒后淡出/消失。

0xE2 0x80 0x99
setTimeout(() => $("#layer").fadeOut(), 2000);
/*
  or if you are not using jQuery - line below
  setTimeout(() => document.getElementById('layer').style.display = 'none', 2000);
*/
#layer {
  position: absolute;
  width: 100%;
  heigth: 100%;
  background: red;
}

答案 2 :(得分:0)

延迟2秒钟首先你必须确保页面加载'$(document).ready'之后你可以使用'setTimeout'。

if (areEqual(a, b, c, d, e)) //...