zoukankan      html  css  js  c++  java
  • setInterval和clearInterval应用小实例

    <!DOCTYPE html>
    <html>
    <head lang="en">
    <meta charset="UTF-8">
    <title>水平动态伸缩</title>
    <link rel="stylesheet" href="水平动态伸缩.css">
    <script>
    window.onload=function(){
    var aa=document.getElementsByTagName("a");
    for(var i=0;i<aa.length;i++){
    aa[i].onmouseover=function() {
    var This = this;
    This.time = setInterval(function () {
    This.style.width = This.offsetWidth + 8 + "px";
    if (This.offsetWidth >= 160) {
    clearInterval(This.time)
    }
    }, 30)
    }

    aa[i].onmouseout=function() {
    var This = this;
    This.time = setInterval(function () {
    This.style.width = This.offsetWidth - 8 + "px";
    if (This.offsetWidth <= 120) {
    This.style.width = "120px";
    clearInterval(This.time)
    }
    }, 30)
    }
    }
    }
    </script>
    </head>
    <body>
    <ul>
    <li><a class="on" href="#">首页</a></li>
    <li><a href="#">新闻</a></li>
    <li><a href="#">娱乐</a></li>
    <li><a href="#">体育</a></li>
    <li><a href="#">金融</a></li>
    </ul>
    </body>
    </html>

    定时器
    <!DOCTYPE html>
    <html>
    <head lang="en">
    <meta charset="UTF-8">
    <title>定时器</title>
    <style>
    .time {
    padding:20px;
    background-color: lightcoral;
    border:3px solid #ff6600;
    }
    </style>
    <script type="text/javascript">
    var attime;
    function clock(){
    var time=new Date();
    attime = time.getHours()+":"+time.getMinutes()+":"+time.getSeconds();
    document.getElementById("clock").value=attime;
    }
    setInterval(clock,100);
    </script>
    </head>
    <body>
    <div class="time">
    <form>
    <input type="text" id="clock" size="20"/>
    </form>
    </div>
    </body>
    </html>









  • 相关阅读:
    Leetcode 242.有效的字母异位词 By Python
    Leetcode 344.反转字符串 By Python
    Leetcode 217.存在重复元素 By Python
    js 动态加载select触发事件
    MUI 里js动态添加数字输入框后,增加、减少按钮无效
    【 jquery 】常用
    MySql 常用语句
    CSS 选择器 知识点
    HTML 符号实体
    log4net 配置
  • 原文地址:https://www.cnblogs.com/liufangdekele/p/6135622.html
Copyright © 2011-2022 走看看