Image map: show an alternative image of areas on hover

Let's say I want to create an interactive group photo with two mouseover effects:

  • a) show the tooltip above and
  • b) highlight the character / show an alternative image.

What I want to do is very similar to this (see map number 2). I want the group photo to be darkened when the page loads and selects each person / shows an alternative image (for example, the same photo, but color) when you hover over the mouse.

I already have an imagemap map with hints (note that areasthis is not entirely accurate, because I need to use a different image).

My code in FIDDLE

+4
source share
2 answers

Here is CodePen.

I managed to find a solution without using JavaScript. Map Example # 2 seemed to use <dl>and elements <dd>, which are pretty vague, but I agreed with that. I think you can do the same with <figure>other more accurate elements. For each element that you hover over, if you are not using areas, you need to have a different “freeze” image so that you can handle any overlapping areas in the rectangles.

HTML

<dl class="map">
  <dd>
    <figcaption>
      <p>Man 1</p>
    </figcaption>
  </dd>
  <dd>
    <figcaption>
      <p>Man 2</p>
    </figcaption>
  </dd>
  <dd>
    <figcaption>
      <p>Man 3</p>
    </figcaption>
  </dd>
  <dd>
    <figcaption>
      <p>Man 4</p>
    </figcaption>
  </dd>
  <dd>
    <figcaption>
      <p>Man 5</p>
    </figcaption>
  </dd>
</dl>


CSS

.map {
  display: block;
  margin: 50px 0px 0px 40px;
  padding: 0px;
  position: relative;
  background: url('map_silhouette_black.png');
  width: 600px;
  height: 400px;
}

.map dd {
  display: block;
  margin: 0px;
  padding: 0px;
  position: absolute;
  cursor: pointer;
}

.map dd figcaption {
  display: none;
  margin: -50px 0px 0px -60px;
  padding: 10px;
  position: relative;
  background: #333;
  color: #FFF;
  font: 14px sans-serif;
  text-align: center;
  border-radius: 100%;
  width: 120px;
  box-sizing: border-box;
}

.map dd figcaption:before {
  content: '';
  display: block;
  position: absolute;
  bottom: -15px;
  left: 50%;
  border: 10px #333 solid;
  border-left-color: transparent;
  border-bottom-color: transparent;
}

.map dd:hover figcaption {
  display: block;
}

.map dd:nth-child(1) {
  top: 20px;
  left: 20px;
  background-position: -20px -20px;
  width: 115px;
  height: 335px;
}

.map dd:nth-child(2) {
  top: 20px;
  left: 135px;
  background-position: -135px -20px;
  width: 115px;
  height: 345px;
}

.map dd:nth-child(3) {
  top: 5px;
  left: 250px;
  background-position: -250px -5px;
  width: 125px;
  height: 385px;
}

.map dd:nth-child(4) {
  top: 25px;
  left: 360px;
  background-position: -360px -25px;
  width: 120px;
  height: 350px;
}

.map dd:nth-child(5) {
  top: 25px;
  left: 470px;
  background-position: -470px -25px;
  width: 110px;
  height: 330px;
}

.map dd:nth-child(1):hover {
  background-image: url('map_silhouette_color1.png');
}

.map dd:nth-child(2):hover {
  background-image: url('map_silhouette_color2.png');
}

.map dd:nth-child(3):hover {
  background-image: url('map_silhouette_color3.png');
}

.map dd:nth-child(4):hover {
  background-image: url('map_silhouette_color4.png');
}

.map dd:nth-child(5):hover {
  background-image: url('map_silhouette_color5.png');
}
+1
source

Check this code:

$(document).ready(function(e) {
    $('.wrapper area').each(function () {
        // Assigning an action to the mouseover event
        $(this).mouseover(function (e) {
            $('.popup').show();
        });
        // Assigning an action to the mouseout event
        $(this).mouseout(function (e) {
            $('.popup').hide();
        });
    });
});
0
source

Source: https://habr.com/ru/post/1541721/


All Articles