แบบสำรวจการวิจัย: บอกให้เราทราบเกี่ยวกับประสบการณ์การใช้งาน Blockly
เริ่มแบบสำรวจ
กลยุทธ์การบล็อกการลาก
กลยุทธ์การลากบล็อกเป็นออบเจ็กต์ที่กำหนดวิธีจัดการการบล็อกบล็อก โดยใช้ตรรกะเพื่อทำให้เป็นบล็อกที่ลากได้
การสร้างกลยุทธ์การลากบล็อกแบบใหม่จะช่วยให้คุณเปลี่ยนวิธีจัดการกับการลากของบล็อกได้โดยที่ไม่ต้องจัดการกับการสร้างการเลือกที่กำหนดเองได้หรือจัดการการเลือก
เช่น คุณอาจต้องการให้การบล็อกซ้ำกันเมื่อลาก แทนการลากตามปกติ กลยุทธ์การบล็อกการลากจะช่วยให้คุณทำเช่นนั้นได้
กลยุทธ์การลากมีวิธีเหมือนกับ IDraggable
ทั้งหมด
นอกเหนือจากเมธอด getRelativeToSurfaceXY
การใช้งาน
หากต้องการสร้างกลยุทธ์การลาก คุณต้องใช้อินเทอร์เฟซ IDragStrategy
ซึ่งต้องใช้เมธอดเดียวกันกับอินเทอร์เฟซ IDraggable
ทั้งหมด ยกเว้นเมธอด getRelativeToSurfaceXY
ที่บล็อกใช้อยู่แล้ว
คุณสามารถทำตามคำแนะนำในการใช้รูปแบบที่ลากได้เพื่อใช้กลยุทธ์การลาก แต่ข้ามการใช้ getRelativeToSurfaceXY()
การใช้งาน
หากต้องการใช้กลยุทธ์การลากที่กำหนดเอง คุณต้องใช้กลยุทธ์การลากกับอินสแตนซ์แต่ละรายการของบล็อก ซึ่งทำได้ในเมธอด init
ของการบล็อก โดยโทรไปที่ setDragStrategy
Blockly.Blocks['my_block'] = {
init: function() {
// Other initialization...
this.setDragStrategy(new MyDragStrategy());
// Other initialization...
}
}
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2024-04-12 UTC
[null,null,["อัปเดตล่าสุด 2024-04-12 UTC"],[[["Block drag strategies dictate how blocks respond to drag events, offering an alternative to custom selectables."],["By implementing the `IDragStrategy` interface, developers can create custom drag behaviors like block duplication on drag."],["Drag strategies encompass the functionality of `IDraggable`, excluding the `getRelativeToSurfaceXY` method, which is handled internally by the block."],["Applying a custom drag strategy requires using `setDragStrategy` within the block's `init` method to associate the strategy with each block instance."]]],["Block drag strategies dictate how a block behaves during drags, allowing for custom drag behaviors like duplication. Developers implement the `IDragStrategy` interface, which mirrors `IDraggable` methods except for `getRelativeToSurfaceXY`. To apply a custom strategy, use the `setDragStrategy` method within a block's `init` method. This enables switching block drag behavior without altering core selection or drag handling. You must implement all the methods of `IDraggable` in the custom strategy except for `getRelativeToSurfaceXY`.\n"]]