#div1 {
width: 100px;
height: 100px;
background: red;
position: absolute;
}
<html>
<head></head>
<body style="height:2000px">
<div id="div1"></div>
</body>
</html>
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';
}