zoukankan      html  css  js  c++  java
  • clearInterval,setInterval,clearTimeout,setTimeout

    setInterval("f()",1000)  每隔1秒就执行一次f()  

    clearInterval   关闭clearInterval 

    setTimeout("f()",1000)  1秒后执行f(),只执行一次

    clearTimeout  关闭setTimeout

    1.简单版应用html代码

    <html> 
    <head> 
    <script type="text/javascript"> 
    var c=0 
    var t 
    function timedCount() { 
    document.getElementById('txt').value=c 
        c=c+1 
        t=setTimeout("timedCount()",1000) 
    } 
    function stopCount() { 
        clearTimeout(t) 
    } 
    </script> 
    </head> 
    <body> 
    <form> 
    <input type="button" value="Start count!" onClick="timedCount()"> 
    <input type="text" id="txt"> 
    <input type="button" value="Stop count!" onClick="stopCount()"> 
    </form> 
    </body> 
    </html> 

    2.文字上下翻滚html代码(无缺陷)

    <script type="text/javascript">
    $(document).ready(function(){
        $n = $("#Tscroll li").length;              //  1.给ul一个高度
        $("#Tscroll ul").css("height",$n*35)
        
        
        $("#Tscroll").mouseenter(function(){        // 不推荐用mouseover
            clearTimeout(ht);                       // 2.停止ht;
        });    
        $("#Tscroll").mouseleave(function(){         // 不推荐用mouseout,
            Tscroll();                                // 3.滚动 Tscroll
        });    
            
    });
    
    
    function Tscroll(){                        //   4.定义 Tscroll
        var f = $("#Tscroll li").length;
        
        var n = parseInt($("#Tscroll ul").css("top"));
        
        if(n<=-f*35+35){
            $("#Tscroll ul").animate({top:0});    
        }else{
            $("#Tscroll ul").animate({top:n-35});    
        }
        ht = setTimeout("Tscroll()",1000);              // 5.每个一秒执行  Tscroll();  整个函数组合起来就是一个无限循环
    }
    Tscroll();
    </script>
  • 相关阅读:
    shell脚本编程
    Linux系统C语言开发环境学习
    Linux系统用户管理及VIM配置
    实验二 Linux系统简单文件操作命令
    实验一 Linux系统与应用准备
    DS01-线性表
    c博客作业 指针
    C博客06-2019-结构体&文件
    c语言博客作业04 数组
    c语言博客作业03 函数
  • 原文地址:https://www.cnblogs.com/wesky/p/3898941.html
Copyright © 2011-2022 走看看