Skip to content
Snippets Groups Projects
Commit a733304f authored by Julian's avatar Julian
Browse files

Display highlight

parent 2fe0f9fd
No related branches found
No related tags found
1 merge request!2Resolve "Implement basic functionality"
<template> <template>
<div @dragover.prevent @drop.prevent="handleDrop" class="grid"> <div
@dragover.prevent="handleDragOver"
@drop.prevent="handleDrop"
class="grid"
>
<slot name="highlight"> <slot name="highlight">
<div id="highlight"></div> <div id="highlight" ref="highlight"></div>
</slot> </slot>
<DragContainer <DragContainer
v-for="item in items" v-for="item in items"
...@@ -35,7 +39,19 @@ export default { ...@@ -35,7 +39,19 @@ export default {
}, },
}, },
methods: { methods: {
handleDragOver(event) {
let data = event.dataTransfer.getData("vueDrag/gridItem");
let element = JSON.parse(data);
let coords = this.getCoords(event.layerX, event.layerY);
this.$refs.highlight.style.display = "block";
this.$refs.highlight.style.gridColumnStart = coords.x + "";
this.$refs.highlight.style.gridRowStart = coords.y + "";
this.$refs.highlight.style.gridColumnEnd = "span " + element.w;
this.$refs.highlight.style.gridRowEnd = "span " + element.h;
},
handleDrop(event) { handleDrop(event) {
this.$refs.highlight.style.display = "none";
let data = event.dataTransfer.getData("vueDrag/gridItem"); let data = event.dataTransfer.getData("vueDrag/gridItem");
let element = JSON.parse(data); let element = JSON.parse(data);
console.log(element); console.log(element);
...@@ -45,12 +61,17 @@ export default { ...@@ -45,12 +61,17 @@ export default {
}), }),
1 1
); );
element.x = let coords = this.getCoords(event.layerX, event.layerY);
1 + Math.trunc(event.layerX / (event.target.offsetWidth / this.cols)); element.x = coords.x;
element.y = element.y = coords.y;
1 + Math.trunc(event.layerY / (event.target.offsetHeight / this.rows));
this.items.push(element); this.items.push(element);
}, },
getCoords(x, y) {
return {
x: Math.ceil(x / (this.$el.offsetWidth / this.cols)),
y: Math.ceil(y / (this.$el.offsetHeight / this.rows)),
};
},
}, },
data() { data() {
return { return {
...@@ -68,6 +89,11 @@ export default { ...@@ -68,6 +89,11 @@ export default {
#highlight { #highlight {
background: darkgrey; background: darkgrey;
border: grey dashed 2px; border: grey dashed 2px;
display: none;
transition: all 2s ease-in-out;
z-index: -1;
pointer-events: none;
user-select: none;
} }
.grid { .grid {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment