<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
body{
background:black;
}
#c1{
background:white;
}
span{
color:white;
}
</style>
<script>
window.onload=function() {
var oC = document.getElementById("c1") ;
var oGC = oC.getContext('2d') ;
var num = 0;
oGC.translate(100,100);
setInterval(function(){
num++;
oGC.save();
oGC.clearRect(0,0,oC.width,oC.height);
oGC.rotate(num*Math.PI/180);
oGC.fillRect(0,0,100,100);
oGC.restore();
},30);
}
</script>
</head>
<body>
<canvas id="c1" width="400" height="400">
<span>不支持canvas浏览器</span>
</canvas>
</body>
</html>
做了一个以坐标(100,100)为中心点旋转的小方块,显示效果不正常,请各位老师指教哪里有错误,谢谢!
将oGC.translate(100,100);写到 oGC.clearRect(0,0,oC.width,oC.height);后面问题解决。