views:

70

answers:

5

Is there any way to make only a non-transparent portion of an image to trigger mouse-over event?

If the mouse travels to the transparent area, the mouse-out should be triggered and the script should listen for any mouse-over event on a layer underneath the image.

Is it possible? Thanks for any input.

Edit: I am looking to do this without using flash.

A: 

As far as I know, not possible so far to detect the transparent portion of an image.

Sarfraz
A: 

You could make a child div with a fixed height to the approximate size of the transparent area, absolutely positioned over it with blank background and border, then add your scripts to acitvate that div, or content within the div.

Kyle Sevenoaks
+1  A: 

You could map out where the transparent portions of the image are (given this chroma-key example, I expect you could do this in client side code in some browsers) and then compare the position of the event on a mousemove event to see if the pointer is over the transparent portion or not. Then you just need to add a variable to track if it was over that portion last time you checked or not.

David Dorward
A: 

Its possible, if you use Flash.

Few tips here

  • load unproportional image using Flash, write click event handlers inside flash, (and pass it to javascript when clicked)
  • load the flash object with transparent flag
  • set the object or embed tag to very big zIndex like 9999 or something to make it on the top
S.Mark
Why **click** events? How do you, in Flash, determine which portions of the image are transparent so you know where to put events?
David Dorward
@David, In flash if you attach click event on image, it can be done only on non-transparent. I just don't have example to show now, but surely I've done and seen others before.
S.Mark
How are click events going to help detect when the mouse moves over the non-transparent areas?
David Dorward
@David, You know, Flash can write codes inside each object like Images, and images can be png or gif, flash understand transparency of images, and putting click event inside images can only hook the part that visible. Well, I understand Its hard to make sense without seeing an example.
S.Mark
Looks like OP just mentioned that he don't want to use flash, so may be I will do when there is chance.
S.Mark
+2  A: 

You can use an image with the old-fashioned <map> and <area> tags. An area tag can trigger javascript mouse events (an example use is this jQuery plugin: jQuery maphilight).
However, there is no good way to create the map dynamically - you'll have to do it manually, or call a server-side service to map it.

Kobi
Thank you. That shows me some path to proceed. Let me wait and see if I could get any more answer.
Nirmal
This is likely your best bet. Decreasingly good ideas include a) layering transparent divs over the non-transparent portion of the image and adding the click event to those divs; and b) using Flash, but that should be a last resort.
Justin Johnson
As you said, I ended up using the classic image maps. Couldn't find any other good method to handle it without flash. My client's website will be behind a relatively slower connection, so had to crush every kilobyte out from the code. Thanks!
Nirmal