Created
March 24, 2017 06:03
-
-
Save hkongm/1a8cbb89b50a8311eebeddb15754f44f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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