当前位置:网站首页>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
边栏推荐
- LiferayPortal JSONWS反序列化漏洞(CVE-2020-7961)分析
- InvalidConnectionAttributeException异常处理
- PHP内存马技术研究与查杀方法总结
- JS obtain mobile phone model and system version
- JVM之虚拟机栈之动态链接
- GSOAP example - calc
- 2020-09-23左右值 右值引用 std::move()
- 2020-09-25 boost库的noncopyable,用于单例模式
- 装饰器模式的应用,包装ServletRequest,增加addParameter方法
- A 2.5D Cancer Segmentation for MRI Images Based on U-Net
猜你喜欢

Gross Tumor Volume Segmentation for Head and Neck Cancer Radiotherapy using Deep Dense Multi-modalit

Automatic Multi-Organ SegmVentation on Abdominal CT With Dense V-Networks

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

Generic paging framework

JVM之方法的绑定机制

kdevelop新建工程

自定义mvc框架实现

Student addition / deletion gaih

Do you know what BFD is? This article explains the principle and usage scenarios of BFD protocol in detail

JVM之TLAB
随机推荐
sublime text3设置运行自己的Makefile
Wechat applet implements the data listener watch, including the watch that destroys the watch and sub attributes
Deep Learning-based Automated Delineation of Head and Neck Malignant Lesions from PET Images
[Huawei certification] the most complete and selected question bank in hcia-datacom history (with answer analysis)
C语言实现一种创建易管理易维护线程的方法
Pointer functions and function pointers
setInterval、setTimeout和requestAnimationFrame
分布式和集群分不清,我们讲讲两个厨子炒菜的故事
JVM之TLAB
证券账号开户安全吗?是靠谱的吗?
自定义控件之下载控件1(DownloadView1)
Middle order traversal of Li Kou 94 binary tree
Mysql5.7 installation tutorial in centos7 under Linux
Gross Tumor Volume Segmentation for Head and Neck Cancer Radiotherapy using Deep Dense Multi-modalit
安装Anaconda后启动JupyterLab需要输入密码
Fully Automated Delineation of Gross Tumor Volume for Head and Neck Cancer on PET-CT Using Deep Lear
Flutter 基础组件之 Text
Alternative implementation of Scrollview pull-down header amplification
完美二叉树、完全二叉树、完满二叉树
另类实现 ScrollView 下拉头部放大