Search code examples
jqueryimagemaponmouseover

Image map on mouse over show div


So I am trying to create multiple image maps on a picture and then based on the image you are hovering over it will pull that specific information from a div that is below the picture and populate it next to the hovered over image.

<div class="runner_div">
  <img src="http://cooleycollective.com/test/slrc/wp-content/uploads/2013/01/Em_full.jpg" width="680" height="705" usemap="#runner_wear" /></a></p>
<map name="runner_wear">
  <area shape="poly" coords="264,18,237,33,243,72,276,83,328,79,311,29," href="#hat" alt="hat"  />
  <area shape="rect" coords="259,69,331,99" href="#" alt="glasses" />

  </map>
</div>

<div class="gear" id=hat>
<h2>Type of hat</h2>
  <p>I love this hat.I wore it when I was running from a bear in the zoo.</p>
</div>
<div class="gear" id="glasses">
  <p>These glasses were hand picked by a Sherpa from Kentucy!</p>
</div>  

I want the divs to stay below, so as to not be hidden, but also to have the functionality to be hoverable when I hover over the image it references. I am not sure if I need to use jQuery for this or even how to create that code.

I feel like the code would do something like: onmouse hover of this imgmap then display the div that this imagemap references. I have no idea what this would look like in code language. Thanks for the help.


Solution

  • I assume you want the popup effet.

    Please see a demo I've prepared for you using your markup

    Here's the working jQuery

    var $popup = $('.popup');
    $('area').on({
      mouseover : function(e){
        var $this = $(this),
            $obj = $('#'+$this.prop('alt'));
    
        $popup.text($obj.text()).css({
          top: e.pageY + 25,
          left: e.pageX - ($popup.width()/2),
        }).show();
      },
      mouseout: function(){
        var $this = $(this),
            $obj = $('#'+$this.prop('alt'));    
    
        $popup.hide(0).empty();
      }
    });