当用户不操作界面(移动和pc),自动隐藏div
无限循坏不要只能执行一次
刚刚进入界面下图,
但是用户不操作界面时候,设置时间自动隐藏上图div,变成就是怎么去判断用户操作界面时候,不隐藏div图一div,用户不操作界面时候变成图二

解决方案 »

  1.   


    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <title> 页面名称 </title>
    <style type="text/css">
    #div1 {
    width: 300px;
    height: 500px;
    background-color: #099;
    }
    #div2 {
    width: 30px;
    height: 500px;
    background-color: #666;
    display: none;
    }
    </style>
    </head>
    <body>
    <div id="div1"></div>
    <div id="div2"></div>
    <script type="text/javascript">
    var timer;
    function hideDiv() {
    clearTimeout(timer);
    timer = setTimeout(function(){
    document.getElementById("div1").style.display = "none";
    document.getElementById("div2").style.display = "block";
    }, 5000);
    }document.getElementById("div2").onclick = function(){
    document.getElementById("div2").style.display = "none";
    document.getElementById("div1").style.display = "block";
    }document.addEventListener("touchstart",hideDiv);
    document.addEventListener("mousedown",hideDiv);
    document.addEventListener("keydown",hideDiv);
    hideDiv();
    </script>
    </body>
    </html>