//requestAnimFrame 封装,可以兼容所有浏览器
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(/* function */ callback, /* DOMElement */ element){
window.setTimeout(callback, 1000 / 60);
};
})(); // example code from mr doob : http://mrdoob.com/lab/javascript/requestanimationframe/ var canvas, context, toggle; init();
animate(); function init() { canvas = document.createElement( 'canvas' );
canvas.width = 512;
canvas.height = 512; context = canvas.getContext( '2d' ); document.body.appendChild( canvas ); }
//注意使用方法,在方法内调用本方法
function animate() {
requestAnimFrame( animate );
draw(); } function draw() { var time = new Date().getTime() * 0.002;
var x = Math.sin( time ) * 192 + 256;
var y = Math.cos( time * 0.9 ) * 192 + 256;
toggle = !toggle; context.fillStyle = toggle ? 'rgb(200,200,20)' : 'rgb(20,20,200)';
context.beginPath();
context.arc( x, y, 10, 0, Math.PI * 2, true );
context.closePath();
context.fill(); }

requestAnimFrame 动画的使用方法的更多相关文章

  1. 解决Ubuntu开关机动画不正常方法

    联想的笔记本,显卡NVIDIA GT218M,默认使用开源的驱动,但挂起后,再唤醒就黑屏回不到桌面. 1.解决办法:安装NVIDIA专有驱动 $sudo apt-get install nvidia- ...

  2. WPF编程,通过Path类型制作沿路径运动的动画一种方法。

    原文:WPF编程,通过Path类型制作沿路径运动的动画一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/article/de ...

  3. android中3种实现动画效果的方法

    3中实现动画的方法:ImageView imgView = (ImageView)findViewById(R.id.imageView_logo); //第一种动画方法,使用AlphaAnimati ...

  4. [学习笔记]jQuery实现一些动画效果的方法

    jQuery实现效果的方法 1,隐藏和显示:hide(),show(),toggle()  // [ˈtɑ:gl]切换 语法: $(selector).hide(speed,callback); $( ...

  5. 在线Youtube视频下载,修改文本,剪切制作动画的最新方法

    刚刚(减去编写本文章的时间,大概20分钟前吧)在看国外最新技术资讯的时候发现有个方法可以让我们快速去下载Youtube上面的视频,不敢独享,我自己都没有怎么玩就所以立刻post上来广而告之,希望对大家 ...

  6. requestAnimFrame动画兼容性封装

    window.requestAnimFrame=function(){ return window.requestAnimationFrame ||window.webkitRequestAnimat ...

  7. 使用swiper.animate时,给一个对象添加两个动画且动画循环的方法

    swiper官网上给对象加一个动画的方法是 <div class="swiper-slide"> <p class="ani" swiper- ...

  8. 去掉activity默认动画效果的方法

    非常多手机都会自带一些Activity切换动画,项目中假设我们须要禁用掉系统Activity切换的动画.能够使用例如以下方法: 一.重写Activity的Them中的windowAnimationSt ...

  9. vue 退出动画无效解决方法

    遇到一个问题:给模态框加入退出动画,进入的动画效果是有的,可是退出的动画就没有了. 写个简单的结构: <div class="mask" v-show="warni ...

随机推荐

  1. 九、Brideg 桥接模式

    设计原理: 代码清单: 抽象类 DisplayImpl public abstract class DisplayImpl { public abstract void rawOpen(); publ ...

  2. JS实现数组去重方法总结(三种常用方法)

    方法一: 双层循环,外层循环元素,内层循环时比较值 如果有相同的值则跳过,不相同则push进数组 Array.prototype.distinct = function(){ var arr = th ...

  3. Unity 2018 By Example 2nd Edition

    Unity is the most exciting and popular engine used for developing games. With its 2018 release, Unit ...

  4. 245. Shortest Word Distance III 单词可以重复的最短单词距离

    [抄题]: Given a list of words and two words word1 and word2, return the shortest distance between thes ...

  5. Ubuntu 18.04学习笔记

    命令行快捷键 https://blog.csdn.net/wanlhr/article/details/80926804 Ubuntu18.04使用vi命令修改文件并保存 vi /opt/teamvi ...

  6. java【基础】正则表达式

    1 字符串判断 java的正则使用的是Pattern以及Matcher来配合使用的. 如果只是用来判断输入的字符串是否符合格式,推荐使用Matcher的matches方法. public static ...

  7. C语言基础课第二次作业

    一.  题目7-1 统计学生成绩 1.实验代码 #include<stdio.h> int main(void) { int i,grade,n; ,b=,c=,d=,e=; scanf( ...

  8. ABP框架系列之十一:(AspNet-Core-ASPNET核心)

    Introduction This document describes ASP.NET Core integration for ASP.NET Boilerplate framework. ASP ...

  9. 13. The Impact of New Technology on Business 新科技对商务的影响

    13. The Impact of New Technology on Business 新科技对商务的影响 (1) New technology links the world as never b ...

  10. JDK、JRE、JVM之间的关系

       JDK.JRE.JVM之间的关系 1.JDK下载地址 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads ...