Jquery中国地图热点效果-鼠标经过弹出提示层信息的简单实例
投稿:jingxian
如下所示:
<!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" />
</div>
</body>
</html>