打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Fixed-sized Workspace

Fixed-sized Workspace

The simplest way to put Blockly into a webpage is to inject it into an empty'div' tag.

Injection

First, include the core Blockly script and the core blocks set. Note that thepath may vary, depending on where your page is in relation to Blockly:

<script src="blockly_compressed.js"></script>
<script src="blocks_compressed.js"></script>

Then include the messages for the user's language (in this case English):

<script src="msg/js/en.js"></script>

Add an empty div somewhere in the page's body and set its size:

<div id="blocklyDiv" style="height: 480px; width: 600px;"></div>

Add the structure of the toolbox (see Defining the Toolboxfor more information) anywhere on the page:

<xml id="toolbox" style="display: none">
  <block type="controls_if"></block>
  <block type="controls_repeat_ext"></block>
  <block type="logic_compare"></block>
  <block type="math_number"></block>
  <block type="math_arithmetic"></block>
  <block type="text"></block>
  <block type="text_print"></block>
</xml>

Finally, call the following to inject Blockly into an empty div. This scriptshould be at the bottom of the page, or called by the onload event.

<script>
  var workspacePlayground = Blockly.inject('blocklyDiv',
      {toolbox: document.getElementById('toolbox')});
</script>

The workspacePlayground variable is not currently used, but it will becomeimportant later when one wants to save the blocks or generate code.If more than one instance of Blockly is injected onto the same page, ensurethat each returned workspace is stored in a different variable.

Test the page in a browser. You should see Blockly's editor filling the div,with seven blocks in the toolbox.Here is a live demo.

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
ITeye Java编程 Spring框架 Ajax技术 agile敏捷软件开发 ruby on r...
简易可视化编程工具
【震惊】Scratch竟然还有这样一本书
PNG in Windows IE
K210模型转换,运行MNIST于MAIX开发板(完整攻略)
新词新译_D_13
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服