Simple hitbox detection in JavaScript
A simple check for when Box A passes a threshold on the x-axis.
A simple check for when Box A passes a threshold on the y-axis.
A simple check for when Box A intersects Box B checking both axis.
The principles will be the same whether you use canvas or regular HTML and CSS like in this example. Please read the comments supplied in the code for more information.