zoukankan      html  css  js  c++  java
  • 延时定时器与间歇定时器

    间歇定时器示例

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
    </head>
    <body>
        <div id="box"></div>
        <script>
            var box = document.getElementById('box');
            var num = 10;
            box.innerHTML = num;
            var timer = setInterval(function(){
                num--;
                if(num < 0){
                    num = 0;
                    clearInterval(timer);
                }
                box.innerHTML = num;
                console.log(num)
            },1000)
    
            
        </script>
    </body>
    </html>

    延时定时器示例

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <style>
            #box {
                width: 200px;
                height: 130px;
                position: relative;
                position: fixed;
                bottom: 0;
                right: 0;
                display: none;
            }
    
            #box img {
                width: 100%;
                height: 100%;
            }
    
            #box span {
                position: absolute;
                top: 0;
                right: 0;
                background: red;
                color: #fff;
                padding: 4px;
                cursor: pointer;
    
            }
        </style>
    </head>
    
    <body>
        <div id="box">
            <span>X</span>
            <img src="images/ad.jpg" alt="">
        </div>
    
        <script>
            var box = document.getElementById('box');
            var close = box.getElementsByTagName('span')[0];
            // 出现广告定时器
            var timer = setTimeout(function () {
                box.style.display = 'block';
                clearTimeout(timer);
            }, 3000);
    
            // 关闭按钮
            close.onclick = function () {
                box.style.display = 'none';
                setTimeout(function () {
                    box.style.display = 'block';
                }, 3000);
            }
        </script>
    </body>
    
    </html>
  • 相关阅读:
    Base64 编解码
    MFC:CTime类和CTimeSpan类
    VC对话框实现添加滚动条实现滚动效果
    组合框控件 -- CComboBox
    快速排序
    归并排序
    插入排序
    堆排序
    Mozilla新特性只支持https网站,再次推动SSL证书普及
    企业如何选择最佳的SSL
  • 原文地址:https://www.cnblogs.com/shihaiying/p/13229920.html
Copyright © 2011-2022 走看看