首页 > 开发 > JS > 正文

JS教程:鼠标悬停文字上显示图片

2024-09-06 12:40:59
字体:
来源:转载
供稿:网友

效果如下所示:

 <html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>js教程:鼠标悬停文字上显示图片</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="/images/logo.gif" onmouseout="hiddenpic();" onmousemove="showpic(this.src);" />
<p></p>
</body>
</html>

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表