Jquery中国地图热点效果-鼠标经过弹出提示层信息的简单实例


Posted in Javascript onFebruary 12, 2014

如下所示:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>Jquery中国地图热点效果-鼠标经过弹出提示层信息的简单实例</title>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
    <script src="JS/jquery-1.8.0.min.js" type="text/javascript"></script>
    <style type="text/css">
        .map img
        {
            width: 496px;
            height: 415px;
        }
        .mapDiv
        {
            width: 140px;
            height: 61px;
            padding: 5px;
            color: #369;
            background: url('Images/dialge.gif') no-repeat;
            position: absolute;
            display: none;
            word-break: break-all;
        }
    </style>
    <script type="text/javascript">
        $(document).ready(function () {
            $("area").each(function () {
                var $x = -55;
                var $y = -80;
                var name = $(this).attr("alt");
                $(this).mouseover(function (e) {
                    var strall = [];
                    strall = $(this).attr("coords").split(",");
                    var x = parseInt(strall[0]);
                    var y = parseInt(strall[3]);
                    var index_num = $(this).index();
                    var dom = "<div class='mapDiv'><p>提示消息<span class='name'></span><span class='num'></span></p></div>";
                    $("body").append(dom);
                    $(".name").text(name);
                    $(".num").text(index_num)
                    $(".mapDiv").css({
                        left: (x + $x) + "px",
                        top: (y + $y) + "px"
                    }).show();
                }).mouseout(function () {
                    $(".mapDiv").remove();
                }).mousemove(function (e) {
                    $(".mapDiv").css({
                        left: (x + $x) + "px",
                        top: (y + $y) + "px"
                    })
                });
            });
            //first load
            show();
            //random
            setInterval(show, 3000); // 注意函数名没有引号和括弧 
        });

        function show() {
            var area = $("area");
            var random = getRandom(area.length);
            $(area[random]).trigger("mouseover");
        }
        function getRandom(n) { return Math.floor(Math.random() * n + 1) }
    </script>
</head>
<body>
    <div class="map">
        <img border="0" usemap="#Map" src="images/1544302yufceen0c3nbjzu.png" />
        <map name="Map" id="Map">
            <area id="beijing" alt="北京" href="forum.php?gid=1" coords="354,140,380,153" shape="rect">
            <area id="shanghai" alt="上海" href="forum.php?gid=3" coords="434,246,462,259" shape="rect">
            <area id="tianjin" alt="天津" href="forum.php?gid=2" coords="382,168,408,180" shape="rect">
            <area id="chongqing" alt="重庆" href="forum.php?gid=4" coords="294,264,320,276" shape="rect">
            <area id="hebei" alt="河北" href="forum.php?gid=5" coords="347,174,374,186" shape="rect">
            <area id="shanxi" alt="山西" href="forum.php?gid=6" coords="322,186,348,198" shape="rect">
            <area id="neimenggu" alt="内蒙古" href="forum.php?gid=7" coords="349,110,388,124" shape="rect">
            <area id="liaoning" alt="辽宁" href="forum.php?gid=8" coords="406,128,432,140" shape="rect">
            <area id="jilin" alt="吉林" href="forum.php?gid=9" coords="427,101,454,115" shape="rect">
            <area id="heilongjiang" alt="黑龙江" href="forum.php?gid=10" coords="424,58,464,73" shape="rect">
            <area id="jiangsu" alt="江苏" href="forum.php?gid=11" coords="404,224,417,250" shape="rect">
            <area id="zhejiang" alt="浙江" href="forum.php?gid=12" coords="413,265,427,291" shape="rect">
            <area id="anhui" alt="安徽" href="forum.php?gid=13" coords="382,236,395,263" shape="rect">
            <area id="fujian" alt="福建" href="forum.php?gid=14" coords="399,300,413,327" shape="rect">
            <area id="jiangxi" alt="江西" href="forum.php?gid=15" coords="371,286,385,313" shape="rect">
            <area id="shandong" alt="山东" href="forum.php?gid=16" coords="373,196,399,208" shape="rect">
            <area id="henan" alt="河南" href="forum.php?gid=17" coords="337,228,364,239" shape="rect">
            <area id="hubei" alt="湖北" href="forum.php?gid=18" coords="329,258,356,271" shape="rect">
            <area id="hunan" alt="湖南" href="forum.php?gid=19" coords="325,294,352,306" shape="rect">
            <area id="guangdong" alt="广东" href="forum.php?gid=20" coords="356,343,382,355" shape="rect">
            <area id="guangxi" alt="广西" href="forum.php?gid=21" coords="302,343,328,355" shape="rect">
            <area id="hainan" alt="海南" href="forum.php?gid=22" coords="313,398,340,411" shape="rect">
            <area id="sichuan" alt="四川" href="forum.php?gid=23" coords="239,265,265,277" shape="rect">
            <area id="guizhou" alt="贵州" href="forum.php?gid=24" coords="283,311,308,324" shape="rect">
            <area id="yunnan" alt="云南" href="forum.php?gid=25" coords="225,337,251,349" shape="rect">
            <area id="shaanxi" alt="陕西" href="forum.php?gid=26" coords="303,224,316,251" shape="rect">
            <area id="gansu" alt="甘肃" href="forum.php?gid=27" coords="179,156,205,168" shape="rect">
            <area id="qinghai" alt="青海" href="forum.php?gid=28" coords="174,206,200,218" shape="rect">
            <area id="ningxia" alt="宁夏" href="forum.php?gid=29" coords="277,188,290,212" shape="rect">
            <area id="xinjiang" alt="新疆" href="forum.php?gid=30" coords="85,140,111,152" shape="rect">
            <area id="xizang" alt="西藏" href="forum.php?gid=31" coords="87,249,113,261" shape="rect">
            <area id="xianggang" alt="香港" href="forum.php?gid=32" coords="379,358,406,370" shape="rect">
            <area id="aomen" alt="澳门" href="forum.php?gid=33" coords="349,371,375,383" shape="rect">
            <area id="taiwan" alt="台湾" href="forum.php?gid=34" coords="434,322,448,348" shape="rect">
        </map>
    </div>
</body>
</html>
Javascript 相关文章推荐
javascript面向对象的方式实现的弹出层效果代码
Jan 28 Javascript
Javascript生成json的函数代码(可以用php的json_decode解码)
Jun 11 Javascript
form表单只提交数据而不进行页面跳转的解决方案
Sep 18 Javascript
jquery解析json格式数据的方法(对象、字符串)
Nov 24 Javascript
JavaScript与jQuery实现的闪烁输入效果
Feb 18 Javascript
js的form表单提交url传参数(包含+等特殊字符)的两种解决方法
May 25 Javascript
JS实现前端缓存的方法
Sep 21 Javascript
Angular2实现组件交互的方法分析
Dec 19 Javascript
Node.js实现mysql连接池使用事务自动回收连接的方法示例
Feb 03 Javascript
解决element-ui里的下拉多选框 el-select 时,默认值不可删除问题
Aug 14 Javascript
vue-axios同时请求多个接口 等所有接口全部加载完成再处理操作
Nov 09 Javascript
JavaScript点击按钮生成4位随机验证码
Jan 28 Javascript
JavaScript cookie的设置获取删除详解
Feb 11 #Javascript
JavaScript新窗口与子窗口传值详解
Feb 11 #Javascript
jquery绑定事件不生效的解决方法
Feb 11 #Javascript
JS将制定内容复制到剪切板示例代码
Feb 11 #Javascript
JS创建自定义表格具体实现
Feb 11 #Javascript
js实现div的切换特效上一个下一个
Feb 11 #Javascript
js中文逗号转英文实现
Feb 11 #Javascript
You might like
风格模板初级不完全修改教程
2006/10/09 PHP
PHP实现的增强性mhash函数
2015/05/27 PHP
PHP调用API接口实现天气查询功能的示例
2017/09/21 PHP
PHP实现普通hash分布式算法简单示例
2018/08/06 PHP
Laravel 手动开关 Eloquent 修改器的操作方法
2019/12/30 PHP
动态刷新 dorado树的js代码
2009/06/12 Javascript
Javascript 两个窗体之间传值实现代码
2009/09/25 Javascript
指定位置如果有图片显示图片,无图片显示广告的JS
2010/06/05 Javascript
jquery新的绑定事件机制on方法的使用方法
2014/04/15 Javascript
在Ubuntu上安装最新版本的Node.js
2014/07/14 Javascript
javascript获得当前的信息的一些常用命令
2015/02/25 Javascript
javascript实时获取鼠标坐标值并显示的方法
2015/04/30 Javascript
JS实现根据用户输入分钟进行倒计时功能
2016/11/14 Javascript
微信小程序录音与播放录音功能
2017/12/25 Javascript
p5.js入门教程之鼠标交互的示例
2018/03/16 Javascript
基于layui实现高级搜索(筛选)功能
2019/07/26 Javascript
javascript设计模式 ? 解释器模式原理与用法实例分析
2020/04/17 Javascript
对vuex中store和$store的区别说明
2020/07/24 Javascript
基于python元祖与字典与集合的粗浅认识
2017/08/23 Python
python获取多线程及子线程的返回值
2017/11/15 Python
python实现发送邮件功能代码
2017/12/14 Python
在dataframe两列日期相减并且得到具体的月数实例
2018/07/03 Python
对python numpy.array插入一行或一列的方法详解
2019/01/29 Python
基于python判断目录或者文件代码实例
2019/11/29 Python
python 图像的离散傅立叶变换实例
2020/01/02 Python
德国BA保镖药房中文网:Bodyguard Apotheke
2021/03/09 全球购物
大学毕业生的自我鉴定
2013/11/30 职场文书
园林资料员岗位职责
2013/12/30 职场文书
庆祝教师节活动方案
2014/01/31 职场文书
厨房管理计划书
2014/04/27 职场文书
还款承诺书范文
2014/05/20 职场文书
大一新生期末自我评价
2014/09/12 职场文书
客户经理岗位职责
2015/01/31 职场文书
2015年幼儿园教研活动总结
2015/03/25 职场文书
新年晚会开场白
2015/05/29 职场文书
英语教学课后反思
2016/02/15 职场文书