我正在尝试让canvas使用excanvas与IE一起工作。然而,它似乎并没有出现在任何地方。
下面的代码可以在除IE之外的所有浏览器上运行。
我试着遵循了excanvas的项目页面上的建议,但没有效果。
任何帮助都将不胜感激!
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="excanvas.compiled.js"></script>
</head>
<body id="body">
<script type="text/javascript">
load();
function load(){
var canvas = document.createElement("canvas");
if(typeof G_vmlCanvasManager !== "undefined")
G_vmlCanvasManager.initElement(canvas);
var ctx = canvas.getContext("2d");
ctx.fillStyle = "#FF0000";
ctx.beginPath();
ctx.arc(50,50,12,0,Math.PI*2,true);
ctx.closePath();
ctx.fill();
document.getElementById("body").appendChild(canvas);
}
</script>
</body>
</html>发布于 2011-12-31 07:51:39
不要问我为什么,但显然在创建静态画布并绘制到它之后,动态创建的画布开始工作……此外,在body的"onload“中调用"load”方法-而不是直接执行-似乎也很重要(同样,为什么它会这样做超出了我的理解)。
下面的解决方案对我来说很好(IE6):
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="excanvas.compiled.js"></script>
</head>
<body onload="load()" id="body">
<canvas id="static" style="display:none"></canvas>
<script type="text/javascript">
function load(){
// Static
var canvas = document.getElementById("static");
var ctx = canvas.getContext("2d");
ctx.fillStyle = "#FF0000";
ctx.beginPath();
ctx.arc(50,50,12,0,Math.PI*2,true);
ctx.closePath();
ctx.fill();
// Dynamic
var canvas = document.createElement("canvas");
if(typeof G_vmlCanvasManager !== "undefined")
G_vmlCanvasManager.initElement(canvas);
var ctx = canvas.getContext("2d");
ctx.fillStyle = "#FF0000";
ctx.beginPath();
ctx.arc(50,50,12,0,Math.PI*2,true);
ctx.closePath();
ctx.fill();
document.getElementById("body").appendChild(canvas);
}
</script>
</body>
</html>https://stackoverflow.com/questions/8684952
复制相似问题