diff options
| author | Hsieh Chin Fan <pham@topo.tw> | 2024-09-15 15:49:23 +0800 |
|---|---|---|
| committer | Hsieh Chin Fan <pham@topo.tw> | 2024-09-15 15:49:24 +0800 |
| commit | 2b42596d8416042d0014cf3603be7e28ede1faa8 (patch) | |
| tree | 0d3df2e82ef7f7bd40fa354c590696d99af67916 /src | |
| parent | 9d956f6e85e7dd89a72b2ca076e1acaa6d8c0130 (diff) | |
fix: Use correct way to set initial position of draggable blocks
Otherwise, inline style 'transform' would be set to 0 when first-time
dragging, 'left' and 'top' would affect draggable area.
Diffstat (limited to 'src')
| -rw-r--r-- | src/dumbymap.mjs | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/dumbymap.mjs b/src/dumbymap.mjs index d8349c6..47c629c 100644 --- a/src/dumbymap.mjs +++ b/src/dumbymap.mjs | |||
| @@ -372,18 +372,17 @@ export const generateMaps = async (container) => { | |||
| 372 | } | 372 | } |
| 373 | 373 | ||
| 374 | if (layout === 'overlay') { | 374 | if (layout === 'overlay') { |
| 375 | let x = 0; | 375 | let [x, y] = [0, 0]; |
| 376 | let y = 0; | ||
| 377 | htmlHolder.blocks.forEach(block => { | 376 | htmlHolder.blocks.forEach(block => { |
| 378 | // Add draggable instance | 377 | // Add draggable instance |
| 379 | block.draggableInstance = new PlainDraggable(block, { | 378 | block.draggableInstance = new PlainDraggable(block, { |
| 380 | handle: block.draggablePart, | 379 | handle: block.draggablePart, |
| 381 | snap: { x: { step: 20 }, y: { step: 20 } }, | 380 | snap: { x: { step: 20 }, y: { step: 20 } }, |
| 382 | autoScroll: false, | 381 | left: x, |
| 382 | top: y, | ||
| 383 | }) | 383 | }) |
| 384 | |||
| 384 | // Set initial postion side by side | 385 | // Set initial postion side by side |
| 385 | block.style.left = `${x}px` | ||
| 386 | block.style.top = `${y}px` | ||
| 387 | x += parseInt(window.getComputedStyle(block).width) + 50 | 386 | x += parseInt(window.getComputedStyle(block).width) + 50 |
| 388 | if (x > window.innerWidth) { | 387 | if (x > window.innerWidth) { |
| 389 | y += 200 | 388 | y += 200 |