Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement