If you use
onmouseover then the image will appear once in odd positions. This is because onmouseover happens
just as the mouse moves over (into) an element.
The following example uses
onmousemove so that the image follows the cursor
as it moves within the element.
Code:
<!DOCTYPE html>
<html>
<head>
<title>Some Title</title>
<style type="text/css">
#follower {
position: absolute;
}
#thebox {
width: 400px;
height: 300px;
outline: red solid thin;
}
</style>
</head>
<body>
<img id="follower" src="http://lorempixel.com/150/150/sports"
height="150" width="150" alt="follow cursor">
<div id="thebox">Big box</div>
<script type="text/javascript">
window.onload = function () {
var follower;
document.getElementById('thebox').onmousemove = function (e) {
var evt = e || window.event;
follower = follower || document.getElementById('follower');
follower.style.left = parseInt(evt.pageX)-170+"px";
follower.style.top = parseInt(evt.pageY)-40+"px";
};
}
</script>
</body>
</html>
Use this as a guide. Otherwise, you'll need to clarify what you are hoping to achieve.
Added: You could set css
display:none for the image and change this within the mousemove event so that it appears. You would then need to also add
onmouseout to hide the image again.