The previous answers may be exactly what you are looking for, and you may have already decided this. But I note that you did not mention jquery anywhere in your post, and all these answers related to this. So for a clean JS solution ...
I assume that the question was formulated so that you already know how to pop up an image? This can be done by encoding an absolutely positioned hidden img tag in html or generated "on the fly" using JS. The first may be simpler if you are new to JS. In my examples, I assume that you did something similar to the following:
<img src="" id="bigImg" style="position:absolute; display:none; visibility:hidden;">
Then you need the onMouseOver function for your sketch. This function should perform three functions:
1) Load the actual image file into the hidden image
2) Put a hidden image
//See below for what to put in place of the xxxx here. document.getElementById('bigImg').style.top = xxxxxxxx; document.getElementById('bigImg').style.left = xxxxxxxx;
3) Display the latent image
document.getElementById('bigImg').style.display = 'block'; document.getElementById('bigImg').style.visibility = 'visible';
Then you will need to capture the onMouseMove event and update the position of the non-hidden image accordingly, using the same code that you would use in (2) above to place the image. It will look something like this:
//Get the mouse position on IE and standards compliant browsers. if (!e) var e = window.event; if (e.pageX || e.pageY) { var curCursorX = e.pageX; var curCursorY = e.pageY; } else { var curCursorX = e.clientX + document.body.scrollLeft; var curCursorY = e.clientY + document.body.scrollTop; } document.getElementById('bigImg').style.top = curCursorY + 1; document.getElementById('bigImg').style.left = curCursorX + 1;
And that was just to do it. Just add the onMouseOut event to hide the BigImg image again. You can change the +1 in the last two lines so that you correctly position the image relative to the cursor.
Please note that all of the above code is for demonstration purposes only; I have not tested any of them, but it should help you on the right track. You can expand this idea further by preloading large images. You can also refuse to capture mousemove events by using setTimeout to update the position every 20 ms or so, although I find this approach more complex and less desirable. I only mention this because some developers (including me when I started) are averse to handling JS events.
I did something similar to this with the custom ColdFusion tag that I wrote to generate floating div users that could click and drag around the screen. The same principle. If you need, I can dig this out to answer any additional questions in more detail.
Good luck