Skip to content

Commit bf21c10

Browse files
committed
Enhance drag-and-drop experience by improving piece styling and size management
- Added CSS rules to disable transitions during dragging for smoother movement. - Updated JavaScript to store and maintain the original size of pieces while dragging. - Cleaned up redundant CSS definitions for the dragging state.
1 parent caeda36 commit bf21c10

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

css/pieces.css

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@
1414
color: transparent !important;
1515
}
1616

17+
/* Disable transitions during drag for smooth movement */
18+
.piece.dragging {
19+
cursor: grabbing;
20+
opacity: 0.8;
21+
z-index: 100;
22+
pointer-events: none;
23+
position: fixed;
24+
transition: none !important; /* Disable transitions for smooth dragging */
25+
}
26+
1727
/* Explicitly disable any ::before or ::after pseudo-elements */
1828
.piece::before,
1929
.piece::after {
@@ -31,13 +41,7 @@
3141
transform: scale(1.1);
3242
}
3343

34-
.piece.dragging {
35-
cursor: grabbing;
36-
opacity: 0.8;
37-
z-index: 100;
38-
pointer-events: none;
39-
position: fixed;
40-
}
44+
/* Note: .piece.dragging is defined above to disable transitions */
4145

4246
/* Move animations */
4347
@keyframes move-piece {

js/drag.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ function handleDragStart(event) {
115115

116116
// Add dragging class for styling and set initial position
117117
pieceElement.classList.add('dragging');
118+
// Store original size to maintain during drag (fixed positioning can lose relative sizing)
119+
pieceElement.style.width = `${rect.width}px`;
120+
pieceElement.style.height = `${rect.height}px`;
118121
pieceElement.style.left = `${rect.left}px`;
119122
pieceElement.style.top = `${rect.top}px`;
120123

@@ -169,6 +172,8 @@ function handleDragEnd(event) {
169172
// Reset position and remove dragging class
170173
dragState.element.style.left = '';
171174
dragState.element.style.top = '';
175+
dragState.element.style.width = '';
176+
dragState.element.style.height = '';
172177
dragState.element.classList.remove('dragging');
173178

174179
// Only process drop if mouse actually moved (was a drag, not just a click)

0 commit comments

Comments
 (0)