سؤال

I am trying to detect if two divs collide each other using query ui

I have something like

<div id='test' >
   <img src='img1.png'/>
  <div id='sensor'></div>
   <img src='img2.png'/>
</div>


<img id='target' src='target.png' />

js

$('#test').draggable();

I need to detect if the sensor div inside the test div collide with the target image. Is this doable using Jquery UI? Thanks for the help!

هل كانت مفيدة؟

المحلول

The Drag and Drop Events might handle what you're trying to accomplish. If you need to detect an exact collision though, you could use mousemove events to be notified whenever things move, then use JQuery's offset(), width() and height() functions to get the coordinates and sizes of each element and compare them to see if the two rectangles intersect.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top