Imagine a scenario where a div element is designed to follow the mouse cursor on the screen. This functionality is achieved by manipulating the document's `mousemove` event and adjusting the div's `left` and `top` positions based on the event data.
In this hypothetical situation, let's assume that the div has a width and height of 10 units.
The goal is for the div to consistently remain centered on the cursor. To achieve this, the `left` and `top` values must be horizontally offset by half of the div's width and vertically offset by half of its height. By doing so, the div will be perfectly centered on the mouse cursor.
document.querySelector(".circle").style.left = e.x - (width / 2)
However, performing this adjustment multiple times throughout the application can become cumbersome. Is there a way to redefine the origin so that setting the `left` and `top` properties does not require offsetting by half the dimensions, as the origin would be at the center of the div itself?
I attempted to use the `transform-origin` property, but it seems to only affect CSS properties related to `transform`, rather than properties like `left`, `margin-left`, etc.
Is there a solution to eliminate the need for these offsets when positioning the div relative to the cursor?