I’m trying to make three canvas to be draggable and at the same time to avoid them from overlapping each other. I looked for similar questions about the topic and I found out about the library “jquery-ui-draggable-collision”. These is the code that I have:
$(document).ready(function(){
$(".cube").draggable({ obstacle: ".obstacle", preventCollision: true });
});
<body>
<canvas class="cube obstacle" id="c"></canvas>
<canvas class="cube obstacle" id="c2"></canvas>
<canvas class="cube obstacle" id="c3"></canvas>
</body>
My problem is that being a canvas the object to drag and the obstacle at the same time makes it not to move at all. I wonder if you can help me out with this.
You could try changing the obstacle selector to something like:
"canvas.obstacle[id!=" + theIdYouDontWant + "]"It should select any other canvas of class obstacle.