View Full Version : Making images appear in Javascript either side of the cursor

12-08-2006, 08:07 PM
Hi Guys,

I'm fairly new to Javascript and wondering if anyone can help? Depending on where the user's cursor is positioned on the web page, I need for two images to appear 10pixels either side of the cursor. I need for these images to appear on a keypress, and to disappear on a keypress too. Does anyone have any ideas for help? Would the code be something like window.event.src????

Many thanks.

This is how far I got so far!!

function myfunction(e)
var keyChar = String.fromCharCode(window.event.keyCode);

if (keyChar == 'N'||keyChar == 'n')
//output 2 images 10 pixels either side of the cursor (either on x or y axes)


12-08-2006, 09:57 PM
Hi Ancora/Mike,

Thanks so much for this script :) I was just trying to play around with it. I was just wondering if you could advise me?

I need to tailor the script so that two images appear either side of the current mouse position (ideally a 10 pixels gap). Once the two images appear, they should stay in the same static position on the page. At the moment using the current script, the images move corresponding to the cursor location. Could you please let me know how to stop these from moving around?


12-08-2006, 10:47 PM

Sorry, that's more than I'm willing to do. The code uses one div, nContainer, for the image, no matter what it is. A new container, well, TWO containers, would have to be created for each "item" you have onmouseover. And then, if that same "item" was hovered again... well, you get the point. It's just too much work.

12-09-2006, 09:36 AM
Hi Ancora/Mike,

I completely understand - thanks a million for your help so far :) If I find the solution, I will let you know.

Best wishes,