JS Image Maps

An image-map is an image with clickable regions.
图象映象是图片的可点区域(一图片多个链接区)


Examples
举例

Simple HTML Image map[简单的图象映象]

Image map with added JavaScript[添加JS的图象映象(多了文字的说明)]


HTML Image Maps
HTML 图象映象

From our HTML tutorial we have learned that an image-map is an image with clickable regions. Normally, each region has an associated hyperlink. Clicking on one of the regions takes you to the associated link.
从HTML教程我们已经学过图象映象是图象中可点击的区域。通常每个区域都有一个相关的链接。点击后会带你去相关的连接上。

Example
举例

The example below demonstrates how to create an HTML image map, with clickable regions. Each of the regions is a hyperlink:
下面的例子演示了怎样建立一个HTML图象映象:

<img src ="planets.gif"
width ="145" height ="126"

alt="Planets"
usemap ="#planetmap" />
<map id ="planetmap"
name="planetmap">
<area shape ="rect" coords ="0,0,82,126"

  href ="sun.htm" target ="_blank"
  alt="Sun" />
<area shape ="circle" coords ="90,58,3"

  href ="mercur.htm" target ="_blank"
  alt="Mercury" />
<area shape ="circle" coords ="124,58,8"

  href ="venus.htm" target ="_blank"
  alt="Venus" />
</map> 

Result结果

Planets Sun Mercury Venus

Adding some JavaScript
添加一些JS

We can add events (that can call a JavaScript) to the <area> tags inside the image map. The <area> tag supports the onClick, onDblClick, onMouseDown, onMouseUp, onMouseOver, onMouseMove, onMouseOut, onKeyPress, onKeyDown, onKeyUp, onFocus, and onBlur events.
我们给图片内的<area>标签里面添加一些事件(可以叫JS)。<area>标签支持onClick,onDblClick,onMouseDown,onMouseUP,onMouseOver,onMouseMove, onMouseOut, onKeyPress, onKeyDown, onKeyUp, onFocus, 和 onBlur事件

Here's the above example, with some JavaScript added:
给上面的例子加入以下JS:

<html>

<head>
<script type="text/javascript">
function writeText(txt)
{
document.getElementById("desc").innerHTML=txt
}
</script>
</head>
<body>
<img src="planets.gif" width="145" height="126"

alt="Planets" usemap="#planetmap" />

<map id ="planetmap" name="planetmap">
<area shape ="rect" coords ="0,0,82,126"

onMouseOver="writeText('The Sun and the gas giant
planets like Jupiter are by far the largest objects
in our Solar System.')"
href ="sun.htm" target ="_blank" alt="Sun" />

<area shape ="circle" coords ="90,58,3"

onMouseOver="writeText('The planet Mercury is very
difficult to study from the Earth because it is
always so close to the Sun.')"
href ="mercur.htm" target ="_blank" alt="Mercury" />

<area shape ="circle" coords ="124,58,8"

onMouseOver="writeText('Until the 1960s, Venus was
often considered a twin sister to the Earth because
Venus is the nearest planet to us, and because the
two planets seem to share many characteristics.')"
href ="venus.htm" target ="_blank" alt="Venus" />
</map> 

<p id="desc"></p>

</body>
</html>
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值