美文网首页
定时器,Math方法

定时器,Math方法

作者: 追逐_e6cf | 来源:发表于2018-08-19 20:10 被阅读0次

    1.定时器:
    setTimeout 只执行一次
    setInterval 循环定时器

    function fn(){
      alert("这是一个定时器");
    }
    
    //setTimeout(fn, 1000);
    //setInterval(fn, 1000);
    

    2.回调函数:用来接收函数的参数

    //setTimeout(fn, 1000);
    //setInterval(fn, 1000);
    

    将fn这个函数作为参数传递到setTimeout和setInterval

    3.同步代码和异步代码:
    同步代码:前面的代码没有执行完,会阻塞后面的代码执行
    异步代码:等满足条件的时间去执行
    异步加载:
    1)定时器,动画帧
    2)事件绑定的内容
    3)Ajax采用的也是异步操作
    4)回调函数

    4.消除定时器
    clearInterval(obj) 清除多次
    clearTimeout(obj) 清除一次性
    var time = setInterval( fn ,2000 );
    clearInterval( time );
    time对应定时器的序列号

    5.Math.PI 圆周率
    Math.abs 绝对值
    Math.floor 向下取整
    Math.ceil 向上取整
    Math.round 四舍五入
    Math.pow 幂函数
    Math.max 取最大值
    Math.min 取最小值
    Math.random() 随机数

            // console.log( Math.PI ) //圆周率;
            // console.log( Math.abs( -1 ) )
            // console.log( Math.abs( 1 ) )
            // console.log( Math.floor( 520.1314 ) );
            // console.log( Math.floor( 520.0000 ) );
            // console.log( Math.ceil( 520.1 ) );
            // console.log( Math.ceil( 520.01 ) );
            // console.log( Math.ceil( 520.00001 ) );
            // console.log( Math.round( 520.53 ) )
            // console.log( Math.round( 520.49 ) )
            // console.log( Math.round( 525 ) )
            // console.log( Math.pow( 2 , 5  ) )//第一个值为底数,第二个为指数;
            // console.log( Math.max( 5,3,4,6,8,7,9,-5 ,999,999) )
            // console.log( Math.min( 5,3,4,6,8,7,9,-5 ,999) )
            // console.log( Math.min( 5,3,4,6,8,7,9,-5 ,999 ) )
            // console.log( Math.random()  )  // [ 0 , 1 )    随机数
            //console.log( Math.sin( Math.PI/6 ) ) //弧度
    

    相关文章

      网友评论

          本文标题:定时器,Math方法

          本文链接:https://www.haomeiwen.com/subject/mqchiftx.html