当前位置:网站首页>Setinterval, setTimeout and requestanimationframe
Setinterval, setTimeout and requestanimationframe
2022-06-29 10:04:00 【Zhan sir (open source byte)】
setTimeoutsetTimeout Delay execution of a piece of code , but setTimeout because EventLoop The existence of , Not 100% on time , One setTimeout It may be expressed in the following form :
// Time delay 1s after , Print hello,world
setTimeout(() => {
console.log('hello,world');
}, 1000)setInterval:setInterval Within a specified time , Repeat a piece of code , And setTimeout similar , It's not on time , And sometimes it is not recommended setInterval Timer , Because it works with some time-consuming code , There will be problems of execution accumulation , It will wait until the time-consuming operation is over , One or more execution timers together , There are performance issues . One setInterval It may be expressed in the following form :
setInterval(() => {
console.log('hello,world');
}, 1000)requestAnimationFrame: Request animation frame , It is html5 Designed specifically for requesting animation API, It is associated with setTimeout Compared with the following advantages :
- According to the refresh rate of different screens , Automatically adjust the timing of executing the callback function .
- When the window is inactive ,
requestAnimationFrameWill stop executing , andsetTimeoutCan't - It has function throttling function
var progress = 0;
var timer = null;
function render() {
progress += 1;
if (progress <= 100) {
console.log(progress);
timer = window.requestAnimationFrame(render);
} else {
cancelAnimationFrame(timer);
}
}
// First frame rendering
window.requestAnimationFrame(render);If you reprint , Please indicate the source : Open source byte https://sourcebyte.cn/article/171.html
边栏推荐
- Deep Learning-based Automated Delineation of Head and Neck Malignant Lesions from PET Images
- 请用已学过的知识编写程序,找出小甲鱼藏在下边这个长字符串中的密码,密码的埋藏点符合以下规律:
- Flutter 基础组件之 Container
- 2019.11.13训练总结
- RecyclerView 通用适配器封装
- 遍历vector容器中的对象的方式
- Fully Automated Gross Tumor Volume Delineation From PET in Head and Neck Cancer Using Deep Learning
- Wechat applet rewrites the page function to realize global logging
- Idea auto completion
- mysql修改自动递增初始值
猜你喜欢

遍历vector容器中的对象的方式

A 3D Dual Path U-Net of Cancer Segmentation Based on MRI

Gmail: how to quickly read all messages

A 2.5D Cancer Segmentation for MRI Images Based on U-Net

Fully Automated Gross Tumor Volume Delineation From PET in Head and Neck Cancer Using Deep Learning

Zabbix4.4 configure the indicators of the monitoring server and solve the garbled graphics pages

float 与 int 相乘产生的令人崩溃的“ 2.3 * 10 = 22 ”

Segmentation of Head and Neck Tumours Using Modified U-net

Gmail:如何快速将邮件全部已读

FreeRTOS(九)——队列
随机推荐
Caused by: org. apache. xerces. impl. io. MalformedByteSequenceException: Invalid byte 3 of 3-byte UTF-8
数据源连接池未关闭的问题 Could not open JDBC Connection for transaction
Mysql5.7 installation tutorial in centos7 under Linux
2020-09-17 gateway业务流程 两个任务:referer认证和非商品模板化
RecyclerView刷新闪烁与删除Item时崩溃问题
Cloud management platform: openstack architecture design and detailed interpretation
2020-09-21 referer字符串切分 boost gateway代码组织层次
CROSSFORMER: A VERSATILE VISION TRANSFORMER BASED ON CROSS-SCALE ATTENTION
Automatic Multi-Organ SegmVentation on Abdominal CT With Dense V-Networks
JVM之方法的绑定机制
JVM之虚拟机栈之动态链接
leetcode MYSQL数据库题目180
leetcode MYSQL数据库题目181
Deep Learning-based Automated Delineation of Head and Neck Malignant Lesions from PET Images
监控数据源连接池使用情况
2020-09-29 非商品模板化代码层次 rapidjson库
Pipeline details of IPC (interprocess communication)
自定义控件之下载控件1(DownloadView1)
另类实现 ScrollView 下拉头部放大
Zabbix4.4 configure the indicators of the monitoring server and solve the garbled graphics pages