zoukankan      html  css  js  c++  java
  • 【Javascript】javascript学习 三十四 JavaScript 图像地图

    图像地图指的是带有可点击区域的图像。

    实例

    简单的 HTML 图像映射
    本例演示一幅没有添加 JavaScript 的图像映射。
    添加了 JavaScript 的图像映射
    本例演示一幅添加了 JavaScript 的图像映射,当鼠标浮动于某个热点上时,会调用 JavaScript 函数来显示热点所对应的星球的简介。

    JavaScript 图像地图

    我们已经从 HTML 教程中了解到,图像地图是带有可点击区域的图像。通常情况下,每个区域是一个相关的超级链接。单击某个区域,就回到达相关的链接。

    实例

    下面的例子演示如何创建带有可点击区域的 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> 

    结果

    添加 JavaScript

    我们可向图像地图内部的 <area> 标签添加(能调用JavaScript的)事件。<area> 标签支持以下事件:onClick、onDblClick、onMouseDown、onMouseUp、onMouseOver、onMouseMove、onMouseOut、onKeyPress、onKeyDown、onKeyUp、onFocus和onBlur。

    这是添加了 JavaScript 的上面的例子:

    <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>
  • 相关阅读:
    [Angular2 Form] Build Select Dropdowns for Angular 2 Forms
    [Angular2 Form] Create Radio Buttons for Angular 2 Forms
    [Angular2 Router] Exiting an Angular 2 Route
    [Angular2 Router] Optional Route Query Parameters
    JS 实现地区,省份,城市,县区4级联动
    Linux web工程部署远程必备软件安装
    [置顶] 白话01背包
    APUE读书笔记-第17章-高级进程间通信
    UVA 10779 Collectors Problem(最大流)
    (二) win8+XAML Binding(数据绑定)
  • 原文地址:https://www.cnblogs.com/cuishao1985/p/1534406.html
Copyright © 2011-2022 走看看