首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Excanvas:不显示在页面上

Excanvas:不显示在页面上
EN

Stack Overflow用户
提问于 2011-12-31 07:13:44
回答 1查看 2.7K关注 0票数 0

我正在尝试让canvas使用excanvas与IE一起工作。然而,它似乎并没有出现在任何地方。

下面的代码可以在除IE之外的所有浏览器上运行。

我试着遵循了excanvas的项目页面上的建议,但没有效果。

任何帮助都将不胜感激!

代码语言:javascript
复制
  <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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-12-31 07:51:39

不要问我为什么,但显然在创建静态画布并绘制到它之后,动态创建的画布开始工作……此外,在body的"onload“中调用"load”方法-而不是直接执行-似乎也很重要(同样,为什么它会这样做超出了我的理解)。

下面的解决方案对我来说很好(IE6):

代码语言:javascript
复制
<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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8684952

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档