是66行 ctx = canvas.getContext("2d"); 出错,应该怎么改?
<html>
<head>
<title>www.3http.com</title>
<style>
body {
background-color:black;
margin:50px;
text-align:center;
} canvas {
border:1px solid #444;
}
</style>
</head>
<body>
<canvas id="cv" width="1000" height="500"></canvas><script type="text/javascript">
var canvas, ctx;
var particles = [];
var NUM_PARTICLES = 1000; function Particle() {
this.x = Math.random() * canvas.width;
this.y = Math.random() * canvas.height; this.xvel = Math.random() * 5 - 2.5;
this.yvel = Math.random() * 5 - 2.5;
} Particle.prototype.update = function() {
this.x += this.xvel;
this.y += this.yvel; this.yvel += 0.1; if (this.x > canvas.width || this.x < 0) {
this.xvel = -this.xvel;
} if (this.y > canvas.height || this.y < 0) {
this.yvel = -this.yvel;
}
} function loop() {
ctx.clearRect(0, 0, canvas.width, canvas.height); for(var i = 0; i < NUM_PARTICLES; i++) {
particles[i].update();
ctx.beginPath();
//ctx.lineWidth = i%6+1;
ctx.lineWidth=particles[i].size
ctx.moveTo(particles[i].x, particles[i].y);
ctx.lineTo(particles[i].x - particles[i].xvel,particles[i].y - particles[i].yvel);
ctx.strokeStyle= particles[i].color
ctx.stroke();
ctx.closePath();
}
setTimeout(loop, 2);
} function load() {
canvas = document.getElementById("cv");
ctx = canvas.getContext("2d"); for(var i = 0; i < NUM_PARTICLES; i++)
{
particles[i]=new Particle();
particles[i].size=i%16+1
particles[i].color="rgb("+i*7%255+", "+(255-i*7%255)+", 255)"
} //ctx.strokeStyle = "rgb(255, 255, 255)";
loop();
}
load() </script>
</body>
</html>

解决方案 »

  1.   

    楼主应该是:ctx = canvas.getContext("2d"); 改为
    var c=document.getElementById("cv");
    var cxt=c.getContext("2d");
      

  2.   

    canvas 这个是个标签 创建的话应该是找到这个标签的ID
      

  3.   

    回复楼上的,我修改了,还是一样的报错,说是没有getContext这个方法。
      

  4.   

    是不是IE9暂时不支持吖……  你走的太前沿啦,html5  IE9现在只是简单的支持很多东西它还不完善的
      

  5.   

    我刚试了别的网站上的效果,ie9支持html5的,很多效果都能看,ie9测试版今早有的,你也可以下载个试试。
      

  6.   

    我刚安装好就出错,后来发现是讯雷的插件问题,我禁用后就很好了,运行html5的三维效果,一点cpu都不占。
      

  7.   

    发现安装ie9后,其它调用webbrowser控件的都不能运行html5
    好像是内核没更新compatible; MSIE 7.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729