我制作了一张地图,当我指向一个区域时,会弹出一个包含一些信息的框。
它适用于 Safari 和 Chrome,但不适用于 Firefox 或 Internet Explorer(如果您想查看它,请访问 samtranum.com/border-barriers)。
如何使下面的代码也可以在 Firefox 和 IE 中运行?
Javascript:
function showTooltip(div, title, desc) {
var left = event.pageX - 200 + 'px';
var top = event.pageY - 700 + 'px';
div.style.display = 'inline';
div.style.position = 'absolute';
div.style.width = '200px';
div.style.top = top;
div.style.left = left;
div.style.backgroundColor = 'white';
div.style.border = 'solid 1px black';
div.style.padding = '10px';
div.innerHTML = '<b>' + title + '</b> <div style="padding-left:10; padding-right:5">' + desc + '</div>';
}
function hideTooltip(div) {
div.style.display = 'none';
}
HTML:
<body>
<div style="display:none" id="t1"></div>
<img src="http://static.squarespace.com/static/516faf88e4b03f8eb2807350/t/519f3bdee4b05327e360c53d/1369390047458/Borders_Map1.jpg" width="472" height="859" usemap="#bordermap"/>
<map name="bordermap">
<area shape="poly" coords="190,321,194,323,199,322,207,328,202,339,216,341,211,352,227,338,217,333,212,330,210,325,205,321,201,318" onMouseOut="hideTooltip(t1)" onMouseOver="showTooltip(t1, 'Central America', 'There is a barrier between Cuba and the American enclave in Guantanamo Bay, and there have been proposals for Belize-Guatemala and Costa-Rica-Nicaragua barriers.')">
等等。从这里开始,每个地区都是一样的。