Blockly 已於 2025 年 11 月 10 日移交給 Raspberry Pi Foundation!請參閱網誌文章和常見問題。
Google uses AI technology to translate content into your preferred language. AI translations can contain errors.
建立工作區
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Blockly 工作區是 Blockly 的最高層級元件。您可以使用這個 UI 以積木程式設計。
如要進一步瞭解工作區及其子元件,請參閱視覺化詞彙表。
插入 div
Blockly 工作區必須插入至 <div> 中,也就是「插入 div」。
注入 div 的大小可以是靜態或動態。視窗大小變更時,div 中的 Blockly 元素會更新大小。
下列程式碼片段顯示靜態大小的插入內容 div 的 HTML:
<div id="blocklyDiv" style="height: 480px; width: 600px;"></div>
注射
注入作業會建立構成工作區 UI 的所有 HTML 子元素。此外,這個函式也會執行所有必要的初始化作業,讓工作區準備就緒。
注入函式可接受注入的 ID div,或注入的 ID div 本身:
// Passes the ID.
const workspace = Blockly.inject('blocklyDiv', { /* config */ });
// Passes the injection div.
const workspace = Blockly.inject(
document.getElementById('blocklyDiv'), { /* config */ });
設定
注入期間,工作區可設定多種選項 (例如版面配置和樣式)。
如要進一步瞭解設定選項,請參閱「設定選項」。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-11-07 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-11-07 (世界標準時間)。"],[],["Blockly workspaces, the UI for block programming, are injected into a designated `\u003cdiv\u003e` element called the \"injection div.\" This div can have a fixed or dynamic size, with Blockly elements resizing accordingly. Injection initializes the workspace UI and readies it for use. The `Blockly.inject()` function, which creates the workspace, accepts either the injection div's ID or the div itself. Workspace configuration, including layout and style, is set during the injection process.\n"]]