Dragop demo 2

Feedback based on physical coordinates

by bursauxa

HTML

<script src="https://unpkg.com/dragop@1.0.0/dist/dragop.min.js"></script>
<div id="app" v-on-drag-aborted="onAbort">
  <h2>Feedback based on physical coordinates</h2>
  <div class="box" v-draggable v-on-drag="onDrag">
    {{ xSelf ? xSelf + ' :: ' + ySelf : 'Drag me over myself...' }}
  </div>
  <div class="box" v-on-drag="onDrag">
    {{ xOther ? xOther + ' :: ' + yOther : '...or over me instead!' }}
  </div>
</div>

CSS

.box {
  border-color: black;
  border-style: dotted;
  border-width: 1px;
  margin: 8px;
  padding: 8px;
  text-align: center;
  user-select: none;
}

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

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

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

Vue

dragop.AddDragopDirectives(Vue);

new Vue({
  el: "#app",
  data: {
    xSelf: null,
    ySelf: null,
    xOther: null,
    yOther: null
  },
  methods: {
  	onDrag: function(evt) {
      dragOverSelf = evt.source.directiveHolder === evt.target.directiveHolder;
    	this.xSelf = dragOverSelf ? evt.target.x : '<somewhere else>';
    	this.ySelf = dragOverSelf ? evt.target.y : '<somewhere else>';
    	this.xOther = dragOverSelf ? '<somewhere else>' : evt.target.x;
    	this.yOther = dragOverSelf ? '<somewhere else>' : evt.target.y;
    },
  	onAbort: function() {
    	this.xSelf = null;
    	this.ySelf = null;
    	this.xOther = null;
    	this.yOther = null;
    }
  }
})