鼠标悬停到页面文字上可以显示图片,效果如图,本例是以图片为例,使用的时候请修改引用!
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>教程:鼠标悬停文字上显示图片</title>
<script language="javascript">
function showPic(sUrl){
var x,y;
x = event.clientX;
y = event.clientY;
document.getElementById("Layer1").style.left = x;
document.getElementById("Layer1").style.top = y;
document.getElementById("Layer1").innerHTML = "<img src=\"" + sUrl + "\">";
document.getElementById("Layer1").style.display = "block";
}
function hiddenPic(){
document.getElementById("Layer1").innerHTML = "";
document.getElementById("Layer1").style.display = "none";
}
</script>
</head>
<body>
<div id="Layer1" style="display:none;position:absolute;z-index:1;"></div>
<img src=http://www.jzxue.com/wangzhankaifa/javascript-ajax/201101/"logo.gif" width="186" height="64" onMouseMove="showPic(this.src);" onMouseOut="hiddenPic();" />
<p></p>
</body>