在不使用<地图>

Creating clickable areas on a png of lakes without the using <map>

本文关键字:地图 gt lt      更新时间:2023-09-26

我一直在为以下问题绞尽脑汁,我会尽可能具体:

我在我设计的一个网站上有一张5个湖泊的图片作为元素。我想让每个湖泊都可以点击,这样我就可以利用灯箱弹出每个湖泊的地图。

问题是——我会使用地图标签来解决这个问题,但我需要定义绝对高度和宽度来提供区域的坐标;我避免定义它,以便我的页面在移动设备上或重新调整窗口大小时能够正确缩放。

实现这一点最有效的方法是什么?

我附上了一张湖泊的图片。该网站的url为:http://pfowp.lowertownish.com/

5个湖泊每个都需要可点击

如果它有助于查看代码,这里是:

<div id="select" style="font-size:20px; text-align:center; display:block;">
    <h2 class="lakesHead">Choose Your Get-A-Way!</h2><hr>
    <img class="landscape" src="/img/theLakes.png" />
    <a href="/reservations/"><button style="text-shadow:0 0 10px white; padding: 20px 35px; color:#264368; font-weight:900; margin: 25px auto 40px; display:block;" class="btn btn-warning shadowMedium"> BOOK YOUR TRIP NOW  </button></a>
    <p id="foodList" style="margin-top:20px"><em>Our remote Canadian lakes offer some of the finest Canadian walleye and trophy northern fishing anywhere. The famous Ogoki and Albany River system have many rapids and pools, which result in excellent spawning and reproduction. As a result the fishing is consistent in its high quality...spring, summer or fall. This water system is not only home to trophy fish but numbers of fish caught during your fishing trip to Canada.</em></p>
</div>

任何帮助都将不胜感激,甚至是指向正确方向的一点。非常感谢。

如果您不想使用<map>,这是一种快速的方法。

将图像放置为具有background-size:cover;div的背景。

如果您将湖泊图像拆分为9个方形div元素,并使用唯一的ID在每个元素上绑定一个点击事件,您还可以在移动设备中保留所需的纵横比

  • 湖1在左上角
  • 2号湖位于顶部中心
  • 湖3在右上角
  • 湖4在左中
  • 中部无湖
  • 5号湖在右中
  • 湖6在左下方
  • 湖6是底部中心5号湖在右下方