Using the script for finding the "click" location

Hi Kirupa! Thanks for your superb and witty insights in to javascript! I’m coming back to it after about 20 years away!!

I’m designing my own version of an image gallery for my website which I’m currently upgrading. I am using your function for finding the precise click position co-ordinates.

Simple question - does the object that I want to move to where I clicked need to live inside the DIV that the clicked object is in? I checked the co-ordinates your excellent function is returning and they are relative to the items I am clicking on and not relative to the window. But the object I want to move is immediately below the “body” in my DOM. So the moving object is not going to where I click.

Which of your lessons do I need to check out to fix this? (I just ordered one of your books by the way!)

Thank you!

Hi Ozyris!
Do you have a link to your example? I’d be happy to take a look.

(Also, glad you like JavaScript enough to order one of my books! JS is definitely a funner language than what it was 20 years ago haha.)

Kirupa :slight_smile:

Hi Kirupa! Thanks for getting back to me so fast!!

Firstly, the site under construction is at

Under the “pics” tab is where the gallery will be. I am building the animation first on a test page at The plan is simple - click on a thumbnail and the image flies out (amongst other things) over the main image. Click another image and the existing large image flies and shrinks back where it came from while another one flies out to replace it. Mouse away from the thumbnails and the large image flies away without being replaced.

Hi Kirupa,

While you were sleep-scripting I did some more work on getting these positions right with lots of success. No trick to it other than putting the two image containers I want to toggle between inside a containing DIV plus adjusting percentages and “relative/absolute” positioning types till I got what I wanted. Not that elegant but it works. Now to do the class change trick…

Received my book today!! Yeah!!

BTW I still have the Nokia snake game code I wrote in Javascript and which used to play in Netscape!! Doesn’t work any more though! Lol! Maybe I should get that running again…

1 Like

That’s great that you were able to figure it out! :slight_smile:

You should totally dig it up and share the code. It would be a shock for a lot of the newer JS developers on what scripts looked like back in the da haha.

Document.write was our best friend!!

I’ll see if I can round it up…

1 Like

Did you post your code on Dynamic Drive at all? When you said ‘snake game’, I immediately thought of a script I used from that site in ~1999.

1 Like

Hi Krilnon! I would not be surprised if someone else hadn’t tried to program the same game in JavaScript. It was immensely popular and of course a nice challenge at the time.

Apparently Snake was first programmed as an arcade game called Blockade in 1976!! It first appeared on mobiles in the Nokia 6610 in 1997. I built my first website using the HTML editor in Netscape in 1994!! Microsoft did not even have a browser back then. Bill Gates didn’t think the Internet would go anywhere. Ha!

Back then you had to use Javascript (which was invented by the Netscape guys), simple as it was, to do anything, even make responsive image based links. All script code was called from inside object tags!! When Microsoft first entered the game they made their own version called JScript. Neither browser would run the other’s scripts. Battle lines were drawn!

I am not quite sure in what year I coded my Snake page. Some time between 1997 and 2004 I had a serious crash on my machines. If I remember correctly it was the Melissa virus - anyone remember that? Also known as Chernobyl. (It was a long time ago - it could have been something else! But I did get attacked by Melissa.) I had to build a fresh clean machine, immunise it against infection and then try to recover the files off of the old HDD using pretty involved data recovery tools which read block by block and tried to reconstruct the files. I lost huge amounts of stuff but somehow Snake was one of the projects that was mostly saved uncorrupted.

So my files are dated 2004 as per when they were rebuilt.

I never posted my code anywhere. But there were lots of versions of Snake done over the years for many platforms. It was real fun to get it working. Maybe if I find an old copy of Netscape and run it in a virtual win95 machine the game might run. If I get some time…

1 Like