【问题标题】:integrate html inside flash cc createjs : not creating createjs text . is that possible to integrate?在 flash cc createjs 中集成 html:不创建 createjs 文本。可以整合吗?
【发布时间】:2016-06-01 07:23:11
【问题描述】:

我试图将这个 h1 插入到 canvas 中。但它没有显示。无论如何要在画布内集成 w3school html 而无需使用easeljs 过程创建文本。我在画布内添加了这个。

  <body onload="init();" style="background-color:#D4D4D4">
<canvas id="canvas" width="550" height="300" style="background-color:#ffffff">
            <h1>  i like this </h1>
            </canvas>


     <script>
        function init() {
            canvas = document.getElementById("canvas");
            exportRoot = new lib.Untitled1();

            stage = new createjs.Stage(canvas);
            stage.addChild(exportRoot);

            stage.update();

            createjs.Ticker.setFPS(24);
            createjs.Ticker.addEventListener("tick", stage);
        }
        </script>
        </head>

        <body onload="init();" style="background-color:#D4D4D4">
<canvas id="canvas" width="550" height="300" style="background-color:#ffffff">
            <h1>  i like this </h1>
            </canvas>

【问题讨论】:

  • 作为后续,您是否有某些原因没有在 Flash 中添加文本然后导出?

标签: javascript canvas createjs


【解决方案1】:

canvas 标记的子元素被视为替代内容,如果浏览器支持 canvas 标记,则不会显示。

由于您已经在使用 createjs,您可以通过 createjs text object 添加文本。这是文档中的一个示例。

var text = new createjs.Text("Hello World", "20px Arial", "#ff7700");
text.x = 100;
text.textBaseline = "alphabetic";
stage.addChild(text);
stage.update();

或者,您可以使用 css 将 html 文本元素放置在 canvas 标记的顶部,如 here 所讨论的那样。

【讨论】:

  • 一个澄清:您在 HTML 中放置在画布中的元素是有效的,实际上是由浏览器处理的——但不会显示,除非画布元素不是浏览器支持。网上有很多代码示例使用子元素在那些浏览器中显示“不支持画布”消息。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-05-10
  • 1970-01-01
  • 2016-08-23
  • 1970-01-01
  • 2015-04-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多