Jquery/JS how to know which block touched another block?

Lord! good evening.

I have 2 blocks A and B.

they are opposite each other between them 10пикселей say

Make the animation of block movement And block In on 15пикселей, I understand the time of their `contact` when the block touched block In those 11пикселе movement.

Well, except for the pixels? There is probably an easier way?
June 14th 19 at 18:53
2 answers
June 14th 19 at 18:55
Download the archive with the game, see the implementation - https://js-master.ru/?Javascripts___Игры___Марио
You can briefly? don't want someone else's code to dig - Alyce_Lesch40 commented on June 14th 19 at 18:58
There's just a working sample, besides the native code.
In short - use method getBoundClientRect() to get the positions of objects. For example, object a has coordinates (a1,a2) , and the object In (b1,b2). Then the condition for imposing on the X-axis when |a1-b1| < A. width/2 + B. width/2 - rhianna_Fee commented on June 14th 19 at 19:01
June 14th 19 at 18:57
I found an example https://ru.stackoverflow.com/questions/630536/%D0%...

but it hurts a lot of code for such a simple thing

Find more questions by tags CSSJavaScriptjQuery