+ 4
Is there any way to make an event happen when two things collide in JavaScript?
I'm confuzzled about how to do it. Like if there was image 1 and image 2, then something, like an alert, should happen when they both collide.
1 ответ
+ 1
Yes, if you write the check for a collision on your own.
If JavaScript is causing the images to move, you could do the equivalent of this after every move:
if (the 2 images are colliding) {
callEliteHackersImageCollisionEventHandler();
}
No, if you're referring only to standard events like "click", "mousedown", "mouseup", "mousemove", "keypress", "touchstart", "focus", "blur", "load", "unload", "submit". Image or element collisions aren't a standard event in JavaScript. The types of events that come standard are related to keyboard, mouse, touchscreen inputs and life cycle. Elements getting close to each other or colliding in the document have no associated events.