Sounds like you would want to use the hover event to detect when the mouse is over the image and then you can display the box on top of the image. You can set the dimensions of the box using CSS width/height and place it with absolute positioning. Use z-index to get it to float over the image.
I’m still not exactly clear what you want to do. Do you want the square to appear anytime the mouse is hovered over the image? If so, then you want to listen for the mouseover (hover) event on the image. Is the square going to be centered on the image or is it going to follow the mouse cursor? Having it centered is fairly easy since you can use CSS to do this.
I’m not going to write the code for you. You will need to research and experiment on your own. This link has a good example of how to add an event listener for mouseover.