当前位置:网站首页>requestAnimationFrame实现浏览器动画
requestAnimationFrame实现浏览器动画
2022-08-09 00:33:00 【彭世瑜】
中文文档:https://developer.mozilla.org/zh-CN/docs/Web/API/Window/requestAnimationFrame
来自MDN的中文文档原文:
window.requestAnimationFrame()
告诉浏览器——你希望执行一个动画,并且要求浏览器在下次重绘之前调用指定的回调函数更新动画。该方法需要传入一个回调函数作为参数,该回调函数会在浏览器下一次重绘之前执行
语法
window.requestAnimationFrame(callback);
代码示例
<div id="app"></div>
<script>
const app = document.getElementById('app')
let count = 0
let delay = 0
function animation() {
// 跳过某一些帧,让数字的变化能够让人眼识别
if (delay % 50 == 0) {
app.innerText = count
count++
}
// 循环调用
window.requestAnimationFrame(animation)
delay++;
}
animation()
</script>
在线Demo: https://mouday.github.io/front-end-demo/requestAnimationFrame.html
边栏推荐
- 图像去雾概述
- 非线性规划——0-1问题、指派问题例子
- 求区间(L, R)小于k的数有多少个
- 【科研-学习-pytorch】5-boardcasting、合并分割
- 动态style定义背景渐变
- 神经网络基本原理
- Use Ehcache distributed cache to easily create commercial-grade high-concurrency, high-performance API interfaces!
- 【科研-学习-pytorch】1-框架特性和常见问题类型
- 5-5 Seaborn库FacetGrid结构图
- "Replay" interview BAMT came back to sort out 398 high-frequency interview questions to help you get a high salary offer
猜你喜欢
随机推荐
笔记&代码 | 统计学——基于R(第四版) 第十一章 时间序列预测
控件限制总结
Using MySQL in Ubuntu/Linux environment: Modify the database sql_mode to solve the "this is incompatible with sql_mode=only_full_group_by" problem
一名双非程序媛面试蚂蚁、美团、携程等大厂拿 offer 分享面试过程
Use Ehcache distributed cache to easily create commercial-grade high-concurrency, high-performance API interfaces!
Use jdbc to handle MySQL's utf8mb4 character set (transfer)
软考总结博客
2021江苏省赛
NodeJs连接mysql数据库
pycharm开启鼠标滚动调节字体大小
[Deep Learning] TensorFlow Learning Road 2: Introduction to ANN and TensorFlow Implementation
4-10 Matplotlib 多图布局
微信企业号开发之接收响应消息
5-3 Seaborn 分布绘图
整流十二 -有效值、平均值、瞬时值、幅值的关系以及相关方法
GaN图腾柱无桥 Boost PFC(单相)三(预测模型)
wordpress入门基本操作,网站安全防护及常用插件(建站必看教程)
千分位数字
Unity3D小白学习日记(01):如何把物体移动到鼠标点击处
【科研-学习-pytorch】5-boardcasting、合并分割