美文网首页
定时器,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方法

    1.定时器:setTimeout 只执行一次setInterval 循环定时器 2.回调函数:用来接收函数...

  • JavaScript 基础

    数据类型: 日期对象: 运算符: 定时器: 字符串常用方法: 数组常用方法: Math常用方法: i的问题(即执行...

  • 定时器和数学对象

    一、定时器: 具体的语法: 二、数学对象: 1、 Math.min() 最小值。var xiao = Math.m...

  • python内置函数

    math模块 在使用前导入math模块 import math 常用方法 math.pow()方法 math.p...

  • JavaScript-3

    这一章节我们来介绍Javascript的Math对象,日期对象,函数以及定时器: Javascript的Math对...

  • JS获取两个数之间的任意随机数

    方法一 方法二 Math.round(),Math.ceil(),Math.floor()的区别1.Math.ro...

  • Math对象

    Math对象的属性 Math对象的方法

  • JS笔记14:数学对象Math

    其他方法多记忆Math Math其他属性或方法:腾讯云-开发者社区-JavaScript-Math[https:/...

  • Math 对象

    Math 对象用于执行数学任务 Math 对象属性 Math 对象方法 abs() abs() 方法可返回数的绝对...

  • Math和Date

    Math对象 Math对象 里面提供的方法,可以帮助我们解决算术问题 提供的方法: Math.random() 返...

网友评论

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

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