【发布时间】:2016-03-06 21:44:56
【问题描述】:
我使用图像映射来指定当用户单击图像上的特定区域时要显示的图像。这是我的代码:
<html>
<body>
<div align="center">
<img id="IMGMAPS" src="base.jpg" border="0" width="802" height="1026" orgWidth="802" orgHeight="1026" usemap="#image-maps" alt="" />
<map name="image-maps" id="IMGMAPS">
<area shape="rect" coords="800,1024,802,1026" alt="Image Map" style="outline:none;" title="Image Map" href="base.jpg" />
<area alt="" title="" href="abc\1.jpg" shape="poly" coords="248,177,365,177,364,257,248,256" style="outline:none;" target="_self" />
<area alt="" title="" href="abc\2.jpg" shape="poly" coords="386,193,501,180,510,258,394,271" style="outline:none;" target="_self" />
<area alt="" title="" href="abc\3.jpg" shape="poly" coords="539,221,650,250,631,327,518,299" style="outline:none;" target="_self" />
<area alt="" title="" href="abc\4.jpg" shape="poly" coords="128,277,222,271,228,369,135,375" style="outline:none;" target="_self" />
<area alt="" title="" href="abc\5.jpg" shape="poly" coords="238,281,352,265,360,325,359,342,250,359" style="outline:none;" target="_self" />
</map>
</div>
</body>
</html>
此代码生成以下图像:
如果用户单击指定的坐标,我想要的是图像 1、2、3、4、5 应该在同一窗口的弹出窗口中打开。
我如何做到这一点?
编辑 1: image
基本图像是单个图像。 1、2、3、4、5是图像上具有特定坐标的区域。每个区域都有一个对应的图像,只有当用户单击具有特定坐标的特定区域时,才会在弹出窗口中打开。
编辑 2: 根据@Edrees 的建议,我进行了以下更改:
添加了 Foundation JS
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.0.1/js/foundation.js" ></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.0.1/js/foundation.min.js" ></script>
<script>
$(document).foundation();
</script>
使用data-reveal-id
<img id="IMGMAPS" src="selfie.jpg" border="0" width="802" height="1026" orgWidth="802" orgHeight="1026" usemap="#image-maps" alt="" data-reveal-id="firstModal" data-reveal />
<map name="image-maps" id="IMGMAPS">
<area shape="rect" coords="800,1024,802,1026" alt="Image Map" style="outline:none;" title="Image Map" href="selfie.jpg" />
<!--<div id="firstModal" class="reveal-modal" data-reveal> -->
<area alt="" title="" href="Shortlisted_selfie\VenkateshSittula.jpg" shape="poly" coords="248,177,365,177,364,257,248,256" style="outline:none;" target="_self" id="firstModal" class="reveal-modal" data-reveal />
<a class="close-reveal-modal">×</a>
<!-- </div> -->
这对我的结果没有任何影响。
编辑 3: 我仍在努力寻找可行的解决方案。再次澄清我在寻找什么:
- 基础图像是具有区域 1、2、3、4、5 的单个图像。
- 每个区域(1、2、3、4、5)都有对应的图像。
- 我想要一个功能,如果我点击区域 1,它对应的图像会在
modal dialog中打开,如果我点击区域 2,它对应的图像会在modal dialog中打开......等等等等所有区域(仅在点击时)。
有解决办法吗?
编辑 4: 根据 Edrees 的解决方案,我能够实现我正在寻找的功能。此外,我需要通过在reveal-modal 的右上角包含一个关闭按钮或链接来微调此解决方案。我看到了一些foundation 文档,发现有一个名为**close-reveal-modal** 的类用于此目的,但我不知道如何在我的解决方案中实现它。我也有尺寸从 612*640 到 900*1600 到 1280*960 到 1920*1080 的图像>...如何确保在模态中打开的图像根据窗口大小按比例调整大小(即图像保持比例)?
使用以下codepen 链接改进解决方案
编辑 5:只要我单独查看此页面,@Edrees 的解决方案就可以完美运行。然而,当我将此页面嵌入 MOJO Portal 时,Foundation CSS 和 JS 完全搞砸了 MOJO Portal 的默认行为。似乎默认 CSS 已被 Foundation 覆盖。有没有人有解决方法?一个普通的 jQuery 来解决这个问题而不使用框架/插件?
编辑 6: 在面对基础框架的问题后,我意识到 Rodrigo Leite 有解决这个问题的答案。虽然,我没有发现任何打开的模式对话框,但它确实给用户一种对话框的感觉,并且足以满足我的要求。
我需要什么改变:
- 我希望“div”覆盖整个窗口
- 图像应显示在窗口/屏幕的中心(垂直和水平)
- 显示映射图像时窗口/屏幕右上角的关闭按钮
- 当图像打开时,用户应该只能单击关闭按钮。窗口/屏幕的所有其他部分都应禁用点击功能/点击屏幕的任何部分,关闭按钮除外
注意:关闭按钮可以以任何形式显示,即图像、按钮等。
【问题讨论】:
-
你需要编写一些javascript来“在同一个窗口中打开一个弹出窗口”,否则只需将
target="_self"切换到target="_blank"即可在新窗口中打开图像 -
你也可以这样做:codepen.io/Edrees21/full/BobqrK 然后你只需要在你的源代码中添加基础js + 一行代码,如示例调用基础模态
-
更新了它,这里是你可以看到代码的链接:codepen.io/Edrees21/pen/BobqrK
-
如果您查看代码,我添加了一些解释/描述。对于您要在模态中打开的每个元素,您需要添加一个唯一属性 data-reveal-id 并将其用作模态对话中的 id,因此在您的情况下,请尝试将其添加到区域标签
标签: javascript jquery html css imagemap