开发者

highlighting image map areas using jquery

开发者 https://www.devze.com 2022-12-21 01:39 出处:网络
I\'m trying to highlight image map areas with jquery hover(), I have highlighting divs which are absolutely positioned over the areas, I\'m trying to display the div on hover but the problem is when

I'm trying to highlight image map areas with jquery hover(),

I have highlighting divs which are absolutely positioned over the areas, I'm trying to display the div on hover but the problem is when the mouse is hovering over a particular area the highlighting happens but disappears quickly even-though the mouse is still hovering the area,

any idea what I'm doing wrong,

        <div class="highlight" id="first_area_highlight"></div>
        <div class="highlight" id="second_area_highlight"></div>
        <map name="worksMap" id="worksMap" class="map-areas">
          <area id="first_area" shape="poly" coords="80,64,176,46,186,95"  />
          <area id="second_area" shape="rect" coords="196,107,272,222"  />
                 .....
        </map>

$(function() {


 开发者_开发技巧  $('.highlight').hide();    
   var id;
   $('area').hover(function() {
     id = $(this).attr('id');
     highlight(id);
   },function() {
     unHighlight(id);
   });

   function highlight(id) {
     $('#' + id + '_highlight').show('slow');
   }
   function unHighlight(id) {
     $('#' + id + '_highlight').hide('slow');
   }

});


the .highlight divs overlap your areas, when hovering over an area, the highlight is shown, but it disappears, because the area loses hover.

What you can do, is to show .highlight on area.mouseenter and hide .highlight on highlight.mouseleave.

Here's the idea:

$('area')
    .mouseenter(function() {
        var id = $(this).attr('id');
        $('#' + id + '_highlight').show('slow');
    });

$('.highlight')
    .mouseleave(function () {
        $(this).hide('slow');
    })
    .hide();


You can try the Raphaël plugin, I haven't tried it myself, but here's a demo of hilighting image maps.

0

精彩评论

暂无评论...
验证码 换一张
取 消