【问题标题】:Responsive Image Map popup响应式图像地图弹出窗口
【发布时间】:2015-12-10 02:44:51
【问题描述】:

我想做一个弹出悬停,所以当用户悬停在图像区域地图上时,jquery 会切换弹出 div 以显示。这部分工作得很好,但我无法正确获取 div 的坐标,尤其是在将窗口调整为平板电脑或移动设备大小之后。

直播网站: https://prodiveinternational.com/international-landing-page/

Plunker: 这是一个plunkr:http://plnkr.co/edit/bcZwn0oUnPGUnwvodo32?p=preview

有没有办法让悬停保持悬停相对于图像地图,以便在屏幕调整大小期间工作?

$(document).ready(function (e) {
  $('img[usemap]').rwdImageMaps();
});

function showHover(modal) {
  $('#dominican').css({left: ($('#earth').offset().left + ( 182)) + 'px', top: ($('#earth').offsetTop) + 'px'});
  $('#mexico').css({left: ($('#earth').offset().left + ( 84)) + 'px', top: ($('#earch').offsetTop) + 'px'});

  console.log('earth width: ', $('#earth').width());
  if (modal === 'dominican') {
    $('#dominican').delay(250).fadeIn(250);
    $('#mexico').delay(250).fadeOut(250);
  } else {
    $('#mexico').delay(250).fadeIn(250);
    $('#dominican').delay(250).fadeOut(250);
  }
}

function hideHover() {
    $('#dominican').delay(250).fadeOut(250);
    $('#mexico').delay(250).fadeOut(250);
}
.pill {
    color: #FFF !important;
    width: 150px;
    height: 60px;
    padding: 10px 20px;
    text-decoration: none !important;
    font-size: 24px;
    overflow: visible;
    display: inline-block;
    line-height: 35px;
    vertical-align: bottom;
}

.footer-title {
    width: 100%;
    display: block;
    text-align: center;
    background-color: #eec364;
    text-transfom: uppercase;
    padding: 6px 0;
    color: #fff;
    margin-top: -5px;
}

.arrow-down {
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 10px solid #eec364;
    margin-left: 45%;
}

#dominican .footer-title {
    background-color: #66b8ec;
}

#dominican .arrow-down {
    border-top: 10px solid #66b8ec;
}

.left-pill {
    border-bottom: 2px solid #e68c5e;
    background-color: #eec364;
    border-bottom-left-radius: 500px;
    border-top-left-radius: 500px;
}

.left-pill:hover {
    background-color: #e68c5e;
    -webkit-transition: all 0.25s ease-out;
    -moz-transition: all 0.25s ease-out;
    -o-transition: all 0.25s ease-out;
    transition: all 0.25s ease-out;
}

.right-pill {
    background: #66b8ec;
    border: 0;
    border-bottom: 2px solid #4b8baf;
    border-bottom-right-radius: 500px;
    border-top-right-radius: 500px;
    font-size: 19px;
    line-height: 19px;
}

.right-pill:hover {
    background: #5eabd6;
    -webkit-transition: all 0.25s ease-out;
    -moz-transition: all 0.25s ease-out;
    -o-transition: all 0.25s ease-out;
    transition: all 0.25s ease-out;
}

.location-popup {
    width: 225px;
    display: none;
    position: absolute;
    top: -78px;
}
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Title</title>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 
  <script src="https://www.prodiveinternational.com/wp-content/themes/prodivemex/js/jquery.rwdImageMaps.min.js"></script>

</head>
<body>
<div style="text-align: center;">
  <div style="position: relative;">
    <div id="mexico" class="location-popup">
      <img
        src="https://prodiveinternational.com/wp-content/uploads/2015/09/11391541_10153361315524938_5579018781886490858_n.jpg"
        style="width:225px;"/><span class="footer-title">Mexico</span>

      <div class="arrow-down"></div>
    </div>
    <div id="dominican" class="location-popup">
      <img
        src="https://prodiveinternational.com/wp-content/uploads/2015/09/11391541_10153361315524938_5579018781886490858_n.jpg"
        style="width:225px;"/><span class="footer-title">Dominican Republic</span>

      <div class="arrow-down"></div>
    </div>
    <img id="earth" style="height:auto; width: 533px;"
         src="https://www.prodiveinternational.com/wp-content/themes/prodivemex/images/Scuba_Map.jpg"
         title="Select Dive Location" usemap="#locations">

    <map name="locations">
      <area id="mexico-link" alt="Mexico" onmouseover="showHover('mexico');" onmouseout="hideHover('mexico')"
            href="https://www.prodivemex.com/" shape="poly" coords="106,186,243,182,241,268,116,264"/>
      <area id="dominican-link" alt="Dominican Republic" onmouseover="showHover('dominican');" onmouseout="hideHover('dominican')"
            href="https://prodiveinternational.com/" shape="poly" coords="273,181,269,268,448,266,442,181"/>
    </map>
  </div>
  <br/>
    <span style="text-align: center; font-size: 32px;">
      Choose Your <strong>Paradise</strong>
      <br/>
      <br/>
      <div>
        <a class="pill left-pill" href="https://www.prodivemex.com/" onmouseover="showHover('mexico');"
           onmouseout="hideHover('mexico')">Mexico</a><a class="pill right-pill"
                                                         href="https://prodiveinternational.com/"
                                                         onmouseover="showHover('dominican');"
                                                         onmouseout="hideHover('dominican')"><span>Dominican<br/> Republic
        </span></a>

        <div style="clear:both"></div>
      </div>
    </span>
</div>
</body>
</html>

【问题讨论】:

    标签: jquery html css popup mousehover


    【解决方案1】:

    我的解决方案并不完全符合我的需要,但可以胜任。我要对具有蒙版的背景图像进行分层。使用完全透明的图像,然后将 div 背景设置为地球。当图像地图区域悬停时,它将在地球顶部分层。透明图像将始终位于顶部,以保持区域和焦点。

      $(document).ready(function (e) {
        $('img[usemap]').rwdImageMaps();
      });
    
      function showHover(modal) {
         $('#earth').addClass('earth-' + modal);
      }
    
      function hideHover(modal) {
        $('#earth').removeClass('earth-' + modal)
      }
    #earth {
      height: auto;
      width: 527px;
      background-image: url(https://www.prodiveinternational.com/wp-content/themes/prodivemex/images/Scuba_Map.jpg);
      background-repeat: no-repeat;
      background-size: contain;
      background-position: center;
      background-size: 100%;
      transition: background-image 1s, transform 1s;
    }
    
    .earth-mexico {
      background-image: url(https://www.prodiveinternational.com/wp-content/themes/prodivemex/images/Scuba_Mexico.png), 
        url(https://www.prodiveinternational.com/wp-content/themes/prodivemex/images/Scuba_Map.jpg) !important;
    }
    
    .earth-dominican {
      background-image: url(https://www.prodiveinternational.com/wp-content/themes/prodivemex/images/Scuba_Dominican.png), 
        url(https://www.prodiveinternational.com/wp-content/themes/prodivemex/images/Scuba_Map.jpg)  !important;
    }
    
    img {
    	max-width: 100%;
    	height: auto;
    }
    .pill {
        color: #FFF !important;
        width: 150px;
        height: 60px;
        padding: 10px 20px;
        text-decoration: none !important;
        font-size: 24px;
        overflow: visible;
        display: inline-block;
        line-height: 35px;
        vertical-align: bottom;
    }
    
    .footer-title {
        width: 100%;
        display: block;
        text-align: center;
        background-color: #eec364;
        text-transfom: uppercase;
        padding: 6px 0;
        color: #fff;
        margin-top: -5px;
    }
    
    .arrow-down {
        width: 0;
        height: 0;
        border-left: 10px solid transparent;
        border-right: 10px solid transparent;
        border-top: 10px solid #eec364;
        margin-left: 45%;
    }
    
    #dominican .footer-title {
        background-color: #66b8ec;
    }
    
    #dominican .arrow-down {
        border-top: 10px solid #66b8ec;
    }
    
    .left-pill {
        border-bottom: 2px solid #e68c5e;
        background-color: #eec364;
        border-bottom-left-radius: 500px;
        border-top-left-radius: 500px;
    }
    
    .left-pill:hover {
        background-color: #e68c5e;
        -webkit-transition: all 0.25s ease-out;
        -moz-transition: all 0.25s ease-out;
        -o-transition: all 0.25s ease-out;
        transition: all 0.25s ease-out;
    }
    
    .right-pill {
        background: #66b8ec;
        border: 0;
        border-bottom: 2px solid #4b8baf;
        border-bottom-right-radius: 500px;
        border-top-right-radius: 500px;
        font-size: 19px;
        line-height: 19px;
    }
    
    .right-pill:hover {
        background: #5eabd6;
        -webkit-transition: all 0.25s ease-out;
        -moz-transition: all 0.25s ease-out;
        -o-transition: all 0.25s ease-out;
        transition: all 0.25s ease-out;
    }
    
    .location-popup {
        width: 225px;
        display: none;
        position: absolute;
        top: -78px;
    }
    <!DOCTYPE html>
    <html lang="en">
    
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Title</title>
      <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    
      <link type="text/css" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
      <script src="https://www.prodiveinternational.com/wp-content/themes/prodivemex/js/jquery.rwdImageMaps.min.js"></script>
    
    
    </head>
    
    <body>
      <div style="text-align: center;">
        <img id="earth" src="https://www.prodiveinternational.com/wp-content/themes/prodivemex/images/Scuba_Blank.png" title="Select Dive Location" usemap="#locations">
        <map name="locations">
          <area id="mexico-link" alt="Mexico" onmouseover="showHover('mexico');" onmouseout="hideHover('mexico')" href="https://www.prodivemex.com/" shape="poly" coords="106,186,243,182,241,268,116,264" />
          <area id="dominican-link" alt="Dominican Republic" onmouseover="showHover('dominican');" onmouseout="hideHover('dominican')" href="https://prodiveinternational.com/" shape="poly" coords="273,181,269,268,448,266,442,181" />
        </map>
        <br/>
        <span style="text-align: center; font-size: 32px;">
          Choose Your <strong>Paradise</strong>
          <br/>
          <br/>
          <div>
            <a class="pill left-pill" href="https://www.prodivemex.com/" onmouseover="showHover('mexico');"
               onmouseout="hideHover('mexico')">Mexico</a><a class="pill right-pill"
                                                             href="https://prodiveinternational.com/"
                                                             onmouseover="showHover('dominican');"
                                                             onmouseout="hideHover('dominican')"><span>Dominican<br/> Republic</span>
            </a>
        <div style="clear:both"></div>
      </div>
      </span>
      </div>
    </body>
    
    </html>

    【讨论】:

      猜你喜欢
      • 2017-03-01
      • 2010-12-01
      • 1970-01-01
      • 2015-08-29
      • 2021-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多