Javascript Help
Posted: Sat Apr 19, 2014 9:59 am
Hey guys!
So although I have programmed in quite a few languages, I am pretty new to javascript. I have a certain task that I require to do in javascript but I am not sure how I would go about it. So the task is simple, lets say I have an image, for an example lets imagine its an image of a farm. Now I want it so that when the user takes his cursor over lets say the farms sheep then a box pops up saying "This is a sheep /*interesting fact goes here*/" or if he takes the mouse over some other animal the same happens for that animal.
I was thinking of going about this two ways, I do not know which would be the best or whether there is a better way to do this:
Way 1:
I thought I'd simply slice up the image, put it back together using CSS (I can imagine this being difficult) and then have javascript functions such as onmouse over for each animal.
Way 2:
I was thinking of using the canvas feature, load up the image onto the canvas, make transparent rectangles around the animals and put the functions on the rectangles (seems messy and not sure if possible)
If you had to do this, would you do any of these ways? If not how would you go about doing something like this?
Thanks!
So although I have programmed in quite a few languages, I am pretty new to javascript. I have a certain task that I require to do in javascript but I am not sure how I would go about it. So the task is simple, lets say I have an image, for an example lets imagine its an image of a farm. Now I want it so that when the user takes his cursor over lets say the farms sheep then a box pops up saying "This is a sheep /*interesting fact goes here*/" or if he takes the mouse over some other animal the same happens for that animal.
I was thinking of going about this two ways, I do not know which would be the best or whether there is a better way to do this:
Way 1:
I thought I'd simply slice up the image, put it back together using CSS (I can imagine this being difficult) and then have javascript functions such as onmouse over for each animal.
Way 2:
I was thinking of using the canvas feature, load up the image onto the canvas, make transparent rectangles around the animals and put the functions on the rectangles (seems messy and not sure if possible)
If you had to do this, would you do any of these ways? If not how would you go about doing something like this?
Thanks!