Click here to Skip to main content
15,881,650 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I have an image from a map and I have several other images from few regions (which are blue) on the image map. The other images represent the blue regions that should show on mouse over. But I have a problem. When I put the mouse over the regions on the image map, they start flashing. For example, I want to activate the blue region WITHOUT THE FLASHING onmouseover and onmousemove when I hover over the specific region. Here is link from the code and the problem that I am having. Please help me if there's anything missing or has to be changed.



http://jsfiddle.net/NPFWm/6/
Posted
Comments
Sergey Alexandrovich Kryukov 7-Jun-13 14:53pm    
Yes, such behavior is easy enough to screw up. But how can we know how exactly you managed to do it? :-)
—SA
Dragan Jovanovski 7-Jun-13 15:30pm    
I post a link with the code, where you can see how it works. http://jsfiddle.net/NPFWm/6/
Sergey Alexandrovich Kryukov 7-Jun-13 15:41pm    
Much better, thank you.
—SA
Sergey Alexandrovich Kryukov 7-Jun-13 16:18pm    
Pretty interesting question, come to thing about, useful for learning — up-voted.
—SA

I cannot fix it immediately, because it would get too much time, as you geometry is complex, but will need big change, but I can explain what's wrong and how can you fix it.

First of all, I removed your flashing code. You can use more compact schema of handling mouse in/out events:
JavaScript
$('.world_map_container area').each(function () {
    // Assigning an action to the mouseover event
    $(this).hover(
        function () {
            var country_id = $(this).attr('id').replace('area_', '');
            // show
       }, 
       function () {
            var country_id = $(this).attr('id').replace('area_', '');
            // hide
        }
    );
});        


Now, if I add you former event handler instead of commented out lines, it will work exactly as your sample. Now let me explain the flashing. You are getting in infinite loop. You handle mouse enter on some element. Then you make some element on top of it visible. It covers the element behind it, which automatically make it not having the mouse pointer in it, and it automatically invokes the mouse-out event.. The handler method below is called, and it causes the shown element hide, which in turn calls the first handle again. Do you see the point?

This way, you cannot play with the properties "display" or "visibility". Instead, you should change the style of the element itself, but you cannot replace one with another, as it will cause flashing. Doing it means changing nearly all your code.

—SA
 
Share this answer
 
v2
Comments
Abhinav S 8-Jun-13 1:08am    
5 for effort and solution.
Sergey Alexandrovich Kryukov 8-Jun-13 20:01pm    
Thank you, Abhinav.
—SA
Sergey Alexandrovich Kryukov 8-Jun-13 20:04pm    
Thank you, Tadit.
—SA
Welcome. :)
Sergey Alexandrovich Kryukov is completely correct about the problem.

And I would give you couple of links to try some other solutions. Might help you.

1. How to apply Hovering on html area tag?[^].
2. maphilight: image map mouseover highlighting[^].
3. A hover image map using Mike Cherim's/Eric Meyer's ideas[^].
 
Share this answer
 
Comments
Dragan Jovanovski 8-Jun-13 16:38pm    
I used the second solution that you provided to me. Thanks a lot. Now it works perfectly. :)
Most Welcome Dragan Jovanovski... :) My pleasure.
Sergey Alexandrovich Kryukov 8-Jun-13 20:05pm    
Next step; a 5. Teamwork!
—SA
Thanks a lot Sergey Alexandrovich Kryukov... :)
Cheers.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900