当前位置:网站首页>setInterval、setTimeout和requestAnimationFrame
setInterval、setTimeout和requestAnimationFrame
2022-06-28 11:09:00 【InfoQ】
setTimeoutsetTimeoutEventLoopsetTimeout// 延时1s之后,打印hello,world
setTimeout(() => {
console.log('hello,world');
}, 1000)
setIntervalsetTimeoutsetIntervalsetIntervalsetInterval(() => {
console.log('hello,world');
}, 1000)
setTimeout- 根据不同屏幕的刷新频率,自动调整执行回调函数的时机。
- 当窗口处于未激活状态时,
requestAnimationFrame会停止执行,而setTimeout不会
- 自带函数节流功能
var progress = 0;
var timer = null;
function render() {
progress += 1;
if (progress <= 100) {
console.log(progress);
timer = window.requestAnimationFrame(render);
} else {
cancelAnimationFrame(timer);
}
}
//第一帧渲染
window.requestAnimationFrame(render);边栏推荐
猜你喜欢

How to use K-line diagram for technical analysis

Oracle 日期格式化异常:无效数字

MySQL (I)

Information hidden in the trend chart of Hong Kong London gold market

零基础自学SQL课程 | IF函数

培训通知|2022年境外中资企业机构及人员疫情防控和安全防范专题培训通知

Katalon全局变量在TestObject引用

Set up your own website (11)

JS基础3

Thesis reading (59):keyword based diverse image retrieval with variable multiple instance graph
随机推荐
Splicing strings in the string collection_ Stream based
移动命令
When an entity is converted to JSON, the field with null value is lost
Introduction to GDB
GCC introduction
[QT] connect syntax reference implementation
Makefile introduction
选择哪种编程语言,会吸引优秀的人才?
Lihongyi, machine learning 7 Conclusion
Datetime and logging module
什么是DAPP系统发展与解析理解
JS基础1-JS引入与运算符
Wireshark数据抓包分析之FTP协议
Wealth management for programmers
【monkey】monkey测试入门
Dataease installation upgrade
Katalon framework tests a web page operation example code
将浏览器中的文件 url转换为File流
使用logrotate对宝塔的网站日志进行自动切割
It is safer for individuals to choose which securities company to open an account for buying floor funds