JSFiddle - React, Tailwind, and code Playground
HTML
<body>
<div id="wrapper" onmousemove="coords(event)" onmouseout="clear_coords()">
<p id="disp"></p>
</div><!--/#wrapper-->
<script>
function coords(test) {
//coordinates of mouse pointer relative to window size in pixels
var x = test.clientX;
var y = test.clientY;
document.getElementById("disp").innerHTML = "Coordinates relative to viewport<br>X coords: " + x + "<br>Y coords: " + y;
}
function clear_coords() {
var win_width = document.getElementById("wrapper").offsetWidth;
var win_height = document.getElementById("wrapper").offsetHeight;
document.getElementById("disp").innerHTML = "X coords: 0<br>Y coords: 0";
}
</script>
CSS
html, body {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
}
body {
background-color: rgba(100,100,100,0.2);
overflow: hidden;
}
#wrapper {
width: 100%;
min-height: 100%;
margin: 0 auto;
position: relative;
}