Dragop demo 1b

Basic SVG drag-and-drop (no feedback)

by bursauxa

HTML

<script src="https://unpkg.com/dragop/dist/dragop.min.js"></script>
<div id="app">
  <h2>Basic SVG drag-and-drop (no feedback)</h2>
  <svg id="playground" width=512 height=256>
    <svg v-for="(paint, index) in paints" :key="paint" :x="index * 128" v-draggable="paint" :fill="paint">
      <rect width=100 height=100 x=14 y=14 />
      <text x=64 y=64>{{ paint }}</text>
    </svg>
    <rect :fill="currentPaint" v-on-drop="onDropped" x="14" y="142" width="484" height="100"/>
    <text x=256 y=192>drop a color here</text>
  </svg>
</div>

CSS

rect {
  stroke: black;
  stroke-width: 1;
}

text {
  text-anchor: middle;
  dominant-baseline: central;
  fill: silver;
}

body {
  background: #20262E;
  padding: 20px;
  font-family: Helvetica;
}

#playground {
  background-color: silver;
  user-select: none;
}

#app {
  background: white;
  border-radius: 4px;
  padding: 20px;
}

h2 {
  font-weight: bold;
  margin-bottom: 15px;
}

Vue

dragop.AddDragopDirectives(Vue);

new Vue({
  el: "#app",
  data: {
    paints: ["red", "green", "blue", "white"],
    currentPaint: undefined
  },
  methods: {
  	onDropped: function(evt) {
    	this.currentPaint = evt.source.data;
    }
  }
})