Convert an absolute point to relative, in different coordinate spaces.
When calling the returned function, the input value must be in the same scale as the intended output scale.
Viewport-relative is used by default.
const f = pointScaler({ to: 'screen' });document.addEventListener('click', evt => { const screenRelative = f(evt.screenX, evt.screenY); // Yields {x,y} on 0..1 scale}); Copy
const f = pointScaler({ to: 'screen' });document.addEventListener('click', evt => { const screenRelative = f(evt.screenX, evt.screenY); // Yields {x,y} on 0..1 scale});
const f = pointScaler({ to: 'viewport' });document.addEventListener('click', evt => { const viewportRelative = f(evt.clientX, evt.clientY); // Yields {x,y} on 0..1 scale}); Copy
const f = pointScaler({ to: 'viewport' });document.addEventListener('click', evt => { const viewportRelative = f(evt.clientX, evt.clientY); // Yields {x,y} on 0..1 scale});
const f = pointScaler({ to: 'document' });document.addEventListener('click', evt => { const documentRelative = f(evt.pageX, evt.pageY); // Yields {x,y} on 0..1 scale}); Copy
const f = pointScaler({ to: 'document' });document.addEventListener('click', evt => { const documentRelative = f(evt.pageX, evt.pageY); // Yields {x,y} on 0..1 scale});
Convert an absolute point to relative, in different coordinate spaces.
When calling the returned function, the input value must be in the same scale as the intended output scale.
Viewport-relative is used by default.