js animation & requestAnimationFrame
js animation & requestAnimationFrame
https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame
window.requestAnimationFrame(callback);
const callback = () => {
window.requestAnimationFrame(callback);
}
// inint
callback();
https://caniuse.com/#feat=requestanimationframe

refs
https://gomakethings.com/how-to-use-requestanimationframe-with-vanilla-js/
https://flaviocopes.com/requestanimationframe/
https://github.com/flaviocopes
https://css-tricks.com/using-requestanimationframe/
http://www.javascriptkit.com/javatutors/requestanimationframe.shtml
See the Pen svg paths (auto player) by xgqfrms
(@xgqfrms) on CodePen.
// define array to store balls
let balls = [];
// define loop that keeps drawing the scene constantly
function loop() {
ctx.fillStyle = 'rgba(0,0,0,0.25)';
ctx.fillRect(0,0,width,height);
while(balls.length < 25) {
var ball = new Ball(
random(0,width),
random(0,height),
random(-7,7),
random(-7,7),
'rgb(' + random(0,255) + ',' + random(0,255) + ',' + random(0,255) +')',
random(10,20)
);
balls.push(ball);
}
for(var i = 0; i < balls.length; i++) {
balls[i].draw();
balls[i].update();
balls[i].collisionDetect();
}
// auto loop
requestAnimationFrame(loop);
}
loop();
generator *function & yield
const log = console.log;
const d = document.querySelector(`[id="svg-path"]`);
log(`d`, d);
// d <path id="svg-path" d="M10 10"></path>
function *test() {
yield d.setAttribute(`d`, `M10 10L10,100`);
yield d.setAttribute(`stroke`, `#0f0`);
yield d.setAttribute(`d`, `M10 10L10,100 H200`);
yield d.setAttribute(`d`, `M10 10L10,100 H200 V10`);
yield d.setAttribute(`d`, `M10 10L10,100 H200 V10 H10`);
yield d.setAttribute(`fill`, `#f0f`);
yield d.setAttribute(`fill`, `#fff7`);
}
let steps = 7;
const loop = () => {
steps = 7;
const app = test();
const flag = setInterval(() => {
if(steps > 0) {
steps--;
app.next(steps);
} else {
clearInterval(flag);
requestAnimationFrame(loop);
}
}, 1000);
}
loop();
requestAnimationFrame 降帧/降频?
refs
xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
js animation & requestAnimationFrame的更多相关文章
- CSS vs. JS Animation: 哪个更快
CSS vs. JS Animation: 哪个更快? CSS vs. JS Animation: 哪个更快? 基于JavaScript的动画竟然已经默默地比CSS的transition动画快了?而且 ...
- CSS3动画 相比JS Animation 哪个更快?
CSS vs. JS Animation: 哪个更快? 基于JavaScript的动画竟然已经默默地比CSS的transition动画快了?而且,Adobe和 Google竟然一直在发布可以媲美原生应 ...
- 微信小游戏 demo 飞机大战 代码分析 (三)(spirit.js, animation.js)
微信小游戏 demo 飞机大战 代码分析(三)(spirit.js, animation.js) 微信小游戏 demo 飞机大战 代码分析(一)(main.js) 微信小游戏 demo 飞机大战 代码 ...
- js动画最佳实现——requestAnimationFrame
我们经常用setInterval来实现动画,其实这种做法不是太好,因为不同浏览器的刷新频率也不一样(一般认为设置16为最佳,按每秒60帧算,1000/60≍16.67) var dis = 0,tim ...
- WebGL与three.js
前面学习了一些webgl的基础知识,现在就用一下three.js写一个小例子,记录一下学习的过程. 效果图: 1.去github下载three.js,然后将它加载到网页中 <script src ...
- 移动端 transition动画函数的封装(仿Zepto)以及 requestAnimationFrame动画函数封装(仿jQuery)
移动端 css3 transition 动画 ,requestAnimationFrame 动画 对于性能的要求,h5优先考虑: 移动端 单页有时候 制作只用到简单的css3动画即可,我们封装一下, ...
- webGL之three.js入门2
入门建议: webGL中文翻译教程,基于NeHe的openGL教程:http://www.hiwebgl.com/?p=42 . WebGL中文网 http://www.hewebgl.com/ ,里 ...
- requestAnimationFrame优势何在?
大概半年前,无意中在网上看到一个新的js函数requestAnimationFrame,据说,此函数可以优化传统的js动画效果,似乎是未来js动画的新方向. 当时我所在的项目正好用到了和js动画有关的 ...
- Three.js基础:建立Cube并实现鼠标交互,动画旋转
index.html文件: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...
随机推荐
- (hive)hive优化(转载)
1. 概述 1.1 hive的特征: 可以通过SQL轻松访问数据的工具,从而实现数据仓库任务,如提取/转换/加载(ETL),报告和数据分析: 它可以使已经存储的数据结构化: 可以直接访问存储在Apac ...
- 使用eventfd创建一个用于事件通知的文件描述符
https://www.jianshu.com/p/57cc1d7d354f nat穿透代码c++
- 原生js使用面向对象的方法开发选项卡实例教程
本教程通过js面向对象的方法来封装一个选项卡的实例,在实例中讲解js的面向对象如何实现功能. 一般封装好的选项卡程序,只需要一个div元素即可.其它元素都是通过json数据来生成,所以封装好的选项卡实 ...
- eclipse项目放到github
一,下载git ,配置用户名和邮箱: git config --global user.name "name" git config --global user.ema ...
- Lambda 表达式 学习
最近几天在学习Lambda,给我的理解就是一个匿名函数的升级版,代码极大可能的简洁了很多,不需要像以前一样必须使用众多的代码才能实现相关功能. 慢慢积累学习,将Java 8的相关知识进行一个学习. 用 ...
- Django(自定义过滤器和自定义标签)
模版是一个用django模版语言标记过的python字符串.模版可以包含模版标签和变量. 模版标签是在一个模版里起作用的标记.比如,一个模版标签可以产生控制结构的内容(if或者for),可以获取数据库 ...
- Centos7 安装RabbitMQ 3.6.1
如果你看过前两章对RabbitMQ已经有了一定了解,现在已经摩拳擦掌,来吧动手吧! 用什么系统 本文使用的是Centos7,为了保证对linux不太熟悉的伙伴也能轻松上手(避免折在安装的路上),下面是 ...
- jvm系列三垃圾回收
三.垃圾回收 1.如何判断对象可以回收 引用计数法 弊端:循环引用时,两个对象的计数都为1,导致两个对象都无法被释放 可达性分析算法 JVM中的垃圾回收器通过可达性分析来探索所有存活的对象 扫描堆中的 ...
- 【奇淫巧技】Bypass阿里云注入
序言 我:摸鱼一时爽,一直摸鱼一时爽啊:relieved:大佬:还摸鱼,快来搞个注入.我:... 拿到数据包 GET /wxapp.php?i=undefined&t=undefined&am ...
- 煎蛋网爬虫之JS逆向解析img路径
图片使用js onload事件加载 <p><img src="//img.jandan.net/img/blank.gif" onload="janda ...