首页 > 解决方案 > 显示第一个 div 并隐藏其余部分,然后在几秒钟后通过隐藏其余部分(包括第一个 div)显示第二个 div

问题描述

我需要通过隐藏 div 的其余部分来显示 div 1 的内容,几秒钟后隐藏第一个并显示第二个 div,几秒钟后通过在 jquery 中显示第三个 div 隐藏第二个 div 和第一个 div。

详细说明如果 div 1 显示隐藏 2nd 和 3rd div,然后通过隐藏 div1 和 div3 在 5 秒后显示 2nd div,然后通过隐藏 div1 和 div 2 在 5 秒后显示 3rd div。

div 的隐藏和显示应该在 5 secs.strong 文本之后

标签: javascripthtmljquerycss

解决方案


要让您的页面等待几秒钟,然后执行某项操作,您需要在下面执行此操作

    //create sleep function
    function sleep(delay) {
    var start = new Date().getTime();
    while (new Date().getTime() < start + delay);
}
  //here you call the function with parameter the secods when you want to sleep you page. 1000 = 1s
  sleep(5000);
  //and here you alert an message after 5s
  alert("hello!");

    //here you can select the div and remove it or display it with js after the sleep 
      document.getElementById("myDIV").style.display = "none";

推荐阅读