Skip to content

Commit e35f446

Browse files
authored
Merge pull request #130 from Pascal-Institute/copilot/add-image-border-rotation
Add rotating dotted border effect during image drag-and-drop
2 parents 07ffa05 + 37228be commit e35f446

2 files changed

Lines changed: 50 additions & 2 deletions

File tree

imgkit/features/image_layer_events.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,16 +224,33 @@ class ImageLayerEvents {
224224
* Setup drag and drop handlers
225225
*/
226226
setupDragDrop() {
227-
// Prevent default browser behavior
228-
this.layer.canvas.addEventListener("dragover", (e) => e.preventDefault());
227+
// Prevent default browser behavior and add rotating border effect
228+
this.layer.canvas.addEventListener("dragover", (e) => {
229+
e.preventDefault();
230+
// Add rotating border animation class
231+
this.layer.panel.classList.add("drag-border-active");
232+
});
229233

230234
this.layer.canvas.addEventListener("dragenter", (e) => {
231235
e.preventDefault();
232236
this.sendLayerEvent("select");
237+
// Add rotating border animation class
238+
this.layer.panel.classList.add("drag-border-active");
239+
});
240+
241+
this.layer.canvas.addEventListener("dragleave", (e) => {
242+
// Only remove class if drag actually left the canvas (not moving to child element)
243+
// Also handle case where relatedTarget is null (e.g., drag left browser window)
244+
if (!e.relatedTarget || !this.layer.canvas.contains(e.relatedTarget)) {
245+
this.layer.panel.classList.remove("drag-border-active");
246+
}
233247
});
234248

235249
this.layer.canvas.addEventListener("drop", async (e) => {
236250
e.preventDefault();
251+
// Remove rotating border animation class
252+
this.layer.panel.classList.remove("drag-border-active");
253+
237254
const files = e.dataTransfer.files;
238255

239256
if (!files || files.length === 0) return;

imgkit/imgpanel.css

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,37 @@
103103
border-top: 3px solid #4caf50;
104104
}
105105

106+
/* Rotating dotted border animation during drag-over */
107+
@keyframes rotating-border {
108+
from {
109+
background-position: 0 0, 100% 100%, 0 100%, 100% 0;
110+
}
111+
to {
112+
background-position: 12px 0, calc(100% - 12px) 100%, 0 calc(100% - 12px),
113+
100% 12px;
114+
}
115+
}
116+
117+
.imgPanel.drag-border-active::before {
118+
content: "";
119+
position: absolute;
120+
top: 0;
121+
left: 0;
122+
right: 0;
123+
bottom: 0;
124+
border-radius: inherit;
125+
pointer-events: none;
126+
z-index: 10;
127+
background-image: linear-gradient(90deg, #666 50%, transparent 50%),
128+
linear-gradient(90deg, #666 50%, transparent 50%),
129+
linear-gradient(0deg, #666 50%, transparent 50%),
130+
linear-gradient(0deg, #666 50%, transparent 50%);
131+
background-size: 12px 3px, 12px 3px, 3px 12px, 3px 12px;
132+
background-position: 0 0, 100% 100%, 0 100%, 100% 0;
133+
background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
134+
animation: rotating-border 0.5s linear infinite;
135+
}
136+
106137
.imgPanel:hover {
107138
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
108139
}

0 commit comments

Comments
 (0)