Back to Snippets

AI Object Recognition Scanning Box JS

Click the scan button and a laser line sweeps down the image, then three labeled boxes appear over it in sequence. The button locks while the scan runs and unlocks when it finishes.

Boxes are built in JavaScript and positioned with percentage values for left, top, width and height, so they stay aligned to the image at any size. Each one is added on a setTimeout that lines up with where the laser is, then a second short timeout adds the class that triggers its scale in transition. Adding the element and its final class in one frame would skip the animation entirely.

Nothing here does real detection. The coordinates and labels are hardcoded in three createBox calls, and that is the part you replace with output from an actual model. Restarting clears the old boxes and forces a reflow through offsetWidth, so the laser animation replays instead of being ignored as unchanged.

191
#javascript
#css
#ai
#computer vision
#scanning
#bounding box
#object recognition
#animation