Public
Edited
Sep 24, 2024
Insert cell
Insert cell
Insert cell
mutable __mouseX = 0
Insert cell
mutable __mouseY = 0
Insert cell
mutable __mouseData = ({
x: 0,
y: 0
})
Insert cell
mouse = {
window.onmousemove = __onmousemove

return __mouseData
}
Insert cell
function __onmousemove (event) {
// https://stackoverflow.com/questions/7790725/javascript-track-mouse-position
let eventDoc, doc, body;
event = event || window.event;
if (event.pageX == null && event.clientX != null) {
eventDoc = (event.target && event.target.ownerDocument) || document;
doc = eventDoc.documentElement;
body = eventDoc.body;

event.pageX = event.clientX +
(doc && doc.scrollLeft || body && body.scrollLeft || 0) -
(doc && doc.clientLeft || body && body.clientLeft || 0);
event.pageY = event.clientY +
(doc && doc.scrollTop || body && body.scrollTop || 0) -
(doc && doc.clientTop || body && body.clientTop || 0 );
}

mutable __mouseData = {
x: event.pageX,
y: event.pageY
}
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more