Skip to content

Instantly share code, notes, and snippets.

@hkongm
Created March 24, 2017 06:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hkongm/1a8cbb89b50a8311eebeddb15754f44f to your computer and use it in GitHub Desktop.
Save hkongm/1a8cbb89b50a8311eebeddb15754f44f to your computer and use it in GitHub Desktop.
// requestAnimationFrame的向下兼容处理
if (!window.requestAnimationFrame) {
window.requestAnimationFrame = function(fn) {
setTimeout(fn, 17);
};
}
于是,动效绘制大致路数会变成这样:
var canvas = document.querySelector('canvas');
var context = canvas.getContext('2d');
// 画布渲染
var render = function () {
// 清除画布
context.clearRect(0, 0, canvas.width, canvas.height);
// 绘制
draw();
// 继续渲染
requestAnimationFrame(render);
};
render();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment