<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
#div1 {
width: 50px;
height: 50px;
background: red;
position: absolute;
}
</style>
<script>
window.onload = function() {
document.onmousemove = function(ev) {
var oEvent = ev || event;
var oDiv = document.getElementById('div1');
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;
oDiv.style.left = oEvent.clientX + scrollLeft + 'px';
oDiv.style.top = oEvent.clientY + scrollTop + 'px';
//alert(oDiv.style.top);
}
}
</script>
</head>
<body style="height:10000px">
<div id="div1"></div>
</body>
</html>