Skip to main content
100%

offsetX / offsetY

✓ Published0🌍 Public
AAjayyy
Last edited Aug 31, 2018
Created on Aug 31, 2018

This example demonstrates how to precisely track the mouse position relative to an HTML element’s content area, accounting for borders, padding, and scroll offsets. A red circle with a smaller black center follows the cursor inside a child div, while the numeric offsets appear in an otherwise empty parent container. The code uses D3's event handling for `mousemove` and `getBoundingClientRect`, combined with `clientLeft`, `clientTop`, and `pageXOffset`/`pageYOffset`, to convert page coordinates into element-local coordinates. The visualization relies solely on D3.js version 2.7.4 and plain DOM styling.

AI-generated description

forked from <a href='http://bl.ocks.org/jasondavies/'>jasondavies</a>'s block: <a href='http://bl.ocks.org/jasondavies/1854606'>offsetX / offsetY</a>

mit Licensed

Similar vizzes