将 Fancybox 与图像映射结合使用
我想知道是否有办法将 fancybox 与图像映射一起使用?
<img src="\path\" usemap="#Map">
<map name="Map" id="Map" >
<area shape="poly" coords="0,0,0,328,145,328" href="#" />
<area shape="poly" coords="0,0,180,0,328,328,142,328" href="#" />
<area shape="poly" coords="328,328,328,0,180,0" href="#" />
</map>
I wonder if there is a way to use the fancybox with Image maps?
<img src="\path\" usemap="#Map">
<map name="Map" id="Map" >
<area shape="poly" coords="0,0,0,328,145,328" href="#" />
<area shape="poly" coords="0,0,180,0,328,328,142,328" href="#" />
<area shape="poly" coords="328,328,328,0,180,0" href="#" />
</map>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那么您想在 fancybox 中显示带有图像映射的单个图像吗?
可以通过多种方式将地图添加到 fancybox 的图像中,
例如,您可以在加载后将其添加到图像中,该图像将使用 id
fancybox-img
加载,因此,使用oncomplete()
回调,我们可以将地图添加到图像中:HTML :
jQuery:
在这里查看它的工作
另一种方法是将内容传递到 fancybox:
HTML:
jQuery:
查看它的工作原理这里
可以通过执行以下操作来改进上述内容以支持多个图像和地图:
HTML:
jQuery:
在这里查看它的工作
注意:我已经在 fancybox 中添加了几个选项,如标题所示,只是为了展示如何添加选项。我还捕获了地图上的点击,因此它没有打开网址并发出警报,只是为了向您显示地图正在运行。
根据评论更新:
啊啊,我误会了。在这种情况下,当用户单击地图项时使用 fancybox 非常简单。最简单的方法是使用 jQuery 选择器
$('map > area')
捕获地图区域上的任何点击。但是,如果您不希望在 fancybox 中打开所有区域,则最好添加到选择器中,例如为要打开 fancybox 的每个区域提供一个类,然后使用选择器$( '地图>区域.fancybox')
:HTML:
jQuery:
请参阅此处的示例
.click()
来捕获类 fancybox < 中地图区域上的任何点击 < em>(您会注意到 www.ask.com 示例将在窗口中打开,另外两个示例将在 fancybox 中打开)。.preventDefault()
方法来阻止浏览器像平常一样跟踪链接。rel
设置类型属性,这允许您设置您想要 fancybox 执行的操作。所以在这个例子中:
So you want to show a single image in a fancybox with an image map?
It is possible to add the map to the image of fancybox in a couple of ways,
For example, you could add it to an image once its loaded, the image will load with the id
fancybox-img
, so using theoncomplete()
callback we can have access to add the map to the image:HTML:
jQuery:
See it working here
The other way is to pass content to the fancybox:
HTML:
jQuery:
See it working here
The above could be improved to support multiple images and maps by doing something like this:
HTML:
jQuery:
See it working here
NOTE: I have added a couple of options to the fancybox, like the title just to show how you can add the options. I also caught the click on the map so it didn't open the url and alerts just to show you the map is working.
Update as per the comments:
Ahh, I misunderstood. In that case, it is quite simple to use a fancybox when a user clicks on a map item. The simplest, is to use the jQuery selector
$('map > area')
to catch any click on an area of a map. However, if you didn't want ALL area's to open in a fancybox, it might be better to add to your selector, for example give each area that you want to open a fancybox a class, then use the selector$('map > area.fancybox')
:HTML:
jQuery:
See the example here
.click()
to catch any clicks on a map area with the class fancybox (you will notice the www.ask.com example will open in the window, the other two open in a fancybox)..preventDefault()
method to stop the browser following the link like it normally would.rel
attribute, this allows you to set what you want the fancybox to do.So in this example: