- Suppose variables x, y, px, py, x1, x2
x: x-position of the actual mouse pointer y: y-position of the actual mouse pointer x1: x-position where we want the mouse to appear x2: y-position where we want the mouse to appear Now, let x + px = x1 px = x1 - x similarly, py = y1 - y Now, px, py is the relative position of x, y with respect to x1, y1. The position where our image cursor will appear with respect to x1, y1 will be given by x + px and y + py for all x, y
- Now, the problem is how to detect clicks since the mouse cursor may not be on the pointer. To do this, we use document.elementFromPoint(x+px, y+py) in which we pass the position of the image cursor. This will gives us the object of the element, the image cursor is on. After obtaining the required object, we can invoke the object.click().
Output: Click here to check the live output
My Personal Notes arrow_drop_up
Please Login to comment...