Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

jQuery Hover Over Image Content Only and Not Alpha

jQuery Hover Over Image Content Only and Not Alpha


Perhaps the title isn't great, but I had a little trouble with the wording...

Basically, is it possible to have jQuery's Hover only fire over the actual content of a png with an alpha channel.

So in the image below;

Only fire on the rectangle and not the alpha channel which make up the rest of the document bounds...

I've tried the obvious $('obj').hover(function(){stuff}) but this fires on the alpha channel too...

The final implementation of this will be for more complex shapes than just a rotated square, so css3 tricks are out for the primary basis, but could be used with a back-up/shim, plus I need to support IE7 and ipad,iphone,ipod....

If there is a CSS2 solution then that would be suitable too. Also any real guidance on this issue is more than welcome. My backup for this will be to have an empty div, display block and position it over the shape and then use that. This will obviously not be ideal for the less square objects.

Any hits or tips are more than welcome.

Thank you

Problem courtesy of:


Yes it is possible depending on the Stacking Context of your elements. Keep in mind that when you do a focus over any particular element on a page, that you are actually focusing all other elements within the same stacking context.

So what you could do is either stop the event from bubbling up the stack (if the element you want to "hover" is lower in the stack that the elements you want to prevent hover effects on), or specifically put in prevent default for onhover events for all elements in the stacking context except for the one you want to actually get a hover effect.

Solution courtesy of: Mike Brant


View additional discussion.

This post first appeared on CSS3 Recipes - The Solution To All Your Style Problems, please read the originial post: here

Share the post

jQuery Hover Over Image Content Only and Not Alpha


Subscribe to Css3 Recipes - The Solution To All Your Style Problems

Get updates delivered right to your inbox!

Thank you for your subscription