연구 설문조사: Blockly 사용 경험을 알려주세요
설문조사 시작
고정 크기 워크스페이스
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Blockly를 웹페이지에 배치하는 가장 간단한 방법은 빈 'div' 태그에 삽입하는 것입니다.
1. 코드 가져오기
애플리케이션에 가장 적합한 방식으로 코드를 가져옵니다.
2. 지역 정의
페이지 본문 어딘가에 빈 div를 추가하고 크기를 설정합니다.
<div id="blocklyDiv" style="height: 480px; width: 600px;"></div>
3. 작업공간 삽입
도구 상자 구조를 정의합니다.
const toolbox = {
"kind": "flyoutToolbox",
"contents": [
{
"kind": "block",
"type": "controls_if"
},
{
"kind": "block",
"type": "controls_repeat_ext"
},
{
"kind": "block",
"type": "logic_compare"
},
{
"kind": "block",
"type": "math_number"
},
{
"kind": "block",
"type": "math_arithmetic"
},
{
"kind": "block",
"type": "text"
},
{
"kind": "block",
"type": "text_print"
},
]
}
마지막으로 다음을 호출하여 정의된 div에 Blockly를 삽입합니다.
const workspace = Blockly.inject('blocklyDiv', {toolbox: toolbox});
workspace
변수는 현재 사용되지 않지만 나중에 블록을 저장하거나 코드를 생성하려고 할 때 중요해집니다.
Blockly 인스턴스가 두 개 이상 동일한 페이지에 삽입된 경우 반환된 각 작업공간이 서로 다른 변수에 저장되어 있는지 확인합니다.
이제 브라우저에서 페이지를 테스트할 수 있습니다. Blockly 편집기가 div를 채우고 툴박스에 7개의 블록이 표시됩니다.
라이브 데모를 참고하세요.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-07-25(UTC)
[[["이해하기 쉬움","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-07-25(UTC)"],[[["Blockly can be easily embedded into a webpage by injecting it into an empty 'div' tag."],["The process involves getting the Blockly code, defining a 'div' element for the workspace, and injecting Blockly with a specified toolbox."],["A workspace variable is returned, which will be important for interacting with the Blockly instance later."]]],["To add Blockly to a webpage, first, obtain the necessary code. Next, create an empty `div` element in the page's body and set its dimensions (e.g., `id=\"blocklyDiv\"`, `height: 480px`, `width: 600px`). Define the toolbox structure using JSON format, specifying the block types. Finally, use `Blockly.inject('blocklyDiv', {toolbox: toolbox})` to insert Blockly into the `div`, storing the result in a `workspace` variable for later use in saving blocks or code generation.\n"]]