zoukankan      html  css  js  c++  java
  • 定时器与MATH的方法

     1 setTimeout()
     2     *          只执行一次
     3     *       clearTimeout()
     4     *
     5     *       setInterval()
     6     *       clearInterval()
     7     *           可以循环执行
     8     *       
     9     *           共同点
    10     *              第一个参数:匿名函数/函数名(还可以是字符串,这个字符串会被当做js代码来解析, 非常不推荐这样写)
    11     *              第二个参数:数字(单位是毫秒,代表间隔时间  1000ms = 1s)
    12     *
    13     *       定时器有最低的刷新频率(最低一般13)
    14 
    15 alert()
    16     *           不把本次弹窗取消,后面的代码不会执行
    17 
    18 eval()
    19     *           可以接受字符串参数,并且会把这个字符串当前js代码来执行。
    20 
    21  /*setTimeout(function () {
    22         alert(1)
    23     },1000)*/
    24 
    25     /*setInterval(function () {
    26         alert(2)
    27     },1000)*/
    28 
    29     //setTimeout(auto,2000)
    30     /*setInterval(function () {
    31         alert(1)
    32     },2000)*/
    33 
    34     //eval("alert(1)")
    35 
    36 
    37 //    function auto(x,y) {
    38 //        alert(x+y)
    39 //    }
    40 
    41 /*    var a = 0;
    42 
    43     var timer = setInterval(function () {
    44         a++;
    45         if(a == 10){
    46             clearInterval(timer)
    47         }
    48         box.innerHTML += a+" "  ;
    49     },100)*/
    50 
    51     var x = setTimeout(function () {
    52         alert(1)
    53     },13)
    54 
    55     clearTimeout(x)

    Math的方法:

    取整
        *           向上/向下/四舍五入
        *
        *       Math.ceil()   //向上
        *       Math.floor()  //向下
        *       Math.round()  //四舍五入
        *
        *       随机数
        *
        *       Math.random()  //  [ 0 ~~ 1)
        *
        *       最大值/最小值
        *       Math.max()
        *       Math.min()
        *
        *       绝对值
        *       Math.abs()
        * */
    
    
    
        var a = 1.5;
    
        //alert(Math.ceil(a))
        //alert(Math.floor(a))
        //alert(Math.round(a))
    
        //alert(Math.random())
    
        //alert(  Math.floor(Math.random()*21+10 ))
    
    
        //alert(Math.max(10,20,21,30,51,7,9,50))
        //alert((Math.min(10,20,21,30,51,7,"-9"  )))
    
        //alert(Math.abs(-9))
        
        alert(Math.sin(30*Math.PI/180))
    
        //alert(0.1+0.2)

    案例:

    1.定时跳转;

    2.图片缓慢加载;

    3.随机色;

  • 相关阅读:
    赫尔维茨公式
    从解析几何的角度分析二次型
    Struts 1 Struts 2
    记一次服务器被入侵的调查取证
    契约式设计 契约式编程 Design by contract
    lsblk df
    Linux Find Out Last System Reboot Time and Date Command 登录安全 开关机 记录 帐号审计 历史记录命令条数
    Infrastructure for container projects.
    更新文档 版本控制 多版本并发控制
    Building Microservices: Using an API Gateway
  • 原文地址:https://www.cnblogs.com/letgo-doo/p/8794996.html
Copyright © 2011-2022 走看看