1

我想批量自定义,但按照在线资源的说明进行操作后,我没有看到浏览器中出现任何内容。

这是示例代码:

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Blockly test</title>
  <!-- core library -->
  <script src="https://unpkg.com/blockly/blockly.min.js"></script>
</head>

<body>
  <div id="editor"></div>
  <xml id="toolbox">
    <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>

  <script>
    Blockly.Blocks['constant_value'] = {
      init: function () {
        this.appendValueInput('VALUE')
          .setCheck('String')
          .appendField('TEST');
        this.setOutput(true, 'Number');
        this.setColour(160);
        this.setTooltip('Returns number of letters in the provided text.');
        this.setHelpUrl('http://www.w3schools.com/jsref/jsref_length_string.asp');
      }
    }
    var workspacePlayground = Blockly.inject('editor',
      { toolbox: document.getElementById('toolbox') });
  </script>
</body>

</html>

如何让 Blockly 编辑器出现?

4

1 回答 1

1

您的 Blockly 工作区看起来不错。问题是缺少 CSS 来为编辑器提供高度和宽度,使其可见:

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Blockly test</title>
  <!-- core library -->
  <script src="https://unpkg.com/blockly/blockly.min.js"></script>
  
  <!-- add CSS to give the editor dimensions -->
  <style>
  #editor {
    width: 100%;
    height: 500px;
  }
  </style>
</head>

<body>
  <div id="editor"></div>
  <xml id="toolbox">
    <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>

  <script>
    Blockly.Blocks['constant_value'] = {
      init: function () {
        this.appendValueInput('VALUE')
          .setCheck('String')
          .appendField('TEST');
        this.setOutput(true, 'Number');
        this.setColour(160);
        this.setTooltip('Returns number of letters in the provided text.');
        this.setHelpUrl('http://www.w3schools.com/jsref/jsref_length_string.asp');
      }
    }
    var workspacePlayground = Blockly.inject('editor',
      { toolbox: document.getElementById('toolbox') });
  </script>
</body>

</html>

我添加的只是:

  <style>
  #editor {
    width: 100%;
    height: 500px;
  }
  </style>
于 2021-07-21T21:14:18.897 回答