jQuery实现鼠标经过弹出提示信息的地图热点效果

2020-05-22 22:00:01易采站长站整理

本文实例讲述了jQuery实现鼠标经过弹出提示信息的地图热点效果。分享给大家供大家参考。具体如下:

这里的jQuery鼠标经过弹出提示信息地图热点效果,很多网站上有用到,送给大家,对作者表示感谢。

运行效果截图如下:

具体代码如下:


<!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="jquery-1.6.2.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('//files.jb51.net/file_images/article/201508/201587110632401.gif') no-repeat; position:absolute; display: none; word-break:break-all; }
</style>
<script type="text/javascript">
$(document).ready(function(){
$("area").each(function(){
var $x=-70;
var $y=-80;
var name=$(this).attr("alt");
$(this).mouseover(function(e){
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({
top: (e.pageY + $y)+"px",
left: (e.pageX + $x)+"px"
}).show("fast");
}).mouseout(function(){
$(".mapDiv").remove();
}).mousemove(function(e){
$(".mapDiv").css({
top: (e.pageY + $y)+"px",
left: (e.pageX + $x)+"px"
})
});
});
})
</script>
</head>
<body>
<div class="map">
<img border="0" usemap="#Map" src="//files.jb51.net/file_images/article/201508/201587110854867.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">