3

I have used code described on below mentioned SO answer Change the image source on rollover using jQuery to change image on mouse over.

$(function() {
    $("img")
    .mouseover(function() { 
        var src = $(this).attr("src").match(/[^\.]+/) + "over.gif";
        $(this).attr("src", src);
    })
    .mouseout(function() {
        var src = $(this).attr("src").replace("over", "");
        $(this).attr("src", src);
    });
});

Problem I am facing is that, my images are in png format which have some transparent areas. That means I have non- rectangular shaped images in my website.

Above JQuery changes image src even when mouse is over on transparent area.

Can someone please suggest some way so that image change occurs only when mouse is hover on visible image area?

6
  • 3
    With simple Javascript/jQuery, you don't have access to the image data. You can't decide whether a part of it is visible or not. Maybe an old school image map could be a solution for you. Commented Oct 13, 2011 at 9:35
  • I am ok with any solution using some div/table surrounding the image Commented Oct 13, 2011 at 9:40
  • @bazmegakapa: Not sure is imagemap supported by all browsers ? Commented Oct 13, 2011 at 9:41
  • It's so ancient, that everything supports it :). And it also made it into HTML5. Commented Oct 13, 2011 at 9:43
  • 4
    here a quick demo with jQuery and map jsfiddle.net/at7g8 Commented Oct 13, 2011 at 9:44

1 Answer 1

1

you can use map html property for this http://jsfiddle.net/u9cYZ/3/

or

you can use css3 mask property check this

http://www.webkit.org/blog/181/css-masks/

http://girliemac.com/blog/2010/09/20/201/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.