Skip to content

Instantly share code, notes, and snippets.

A mousemove utility to get the x coordinate of an element or the window. Coordinates are left-based, but we might want to get the x coordinates originating from the right instead. To do this we need to do a bit of maths.

This little function utility (using jQuery) logs to the console the x-left and x-right coordinates.

Example on Codepen.

function mouseXCoords(element) {
	var obj = {