如何制作弹出层

cjfriends 2010-11-16 04:29:17
就想csdn回复的帖子一样,在鼠标移到每个回复者的头像上时会弹出一个层,上面显示一些信息?弹出层很好做,但如何定位才能使层始终出现在头像的旁边?
请各位高手指点一下或者给个例子,不胜感激!
...全文
177 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
cjfriends 2010-11-16
  • 打赏
  • 举报
回复
下班了,结贴了
cjfriends 2010-11-16
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 snowwinner 的回复:]
我晕倒了为什么我那么实用的东西没人用汗颜
[/Quote]

呵呵,不是我不用,而是主管不用,我说了不算
snowwinner 2010-11-16
  • 打赏
  • 举报
回复
我晕倒了为什么我那么实用的东西没人用汗颜
TearsStoneJava 2010-11-16
  • 打赏
  • 举报
回复
====1、将以下的代码加入到HEML的<head></head>之间:

<!-- 以下代码是设定smile的代码 -->
<script LANGUAGE="JavaScript">
var newtop=0
var newleft=0
if (navigator.appName == "Netscape") {
layerStyleRef="layer.";
layerRef="document.layers";
styleSwitch="";
}
else
{
layerStyleRef="layer.style.";
layerRef="document.all";
styleSwitch=".style";
}
function doMouseMove() {
layerName = 'iit'
eval('var curElement='+layerRef+'["'+layerName+'"]')
eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="hidden"')
eval('curElement'+styleSwitch+'.visibility="visible"')
eval('newleft=document.body.clientWidth-curElement'+styleSwitch+'.pixelWidth')
eval('newtop=document.body.clientHeight-curElement'+styleSwitch+'.pixelHeight')
eval('height=curElement'+styleSwitch+'.height')
eval('width=curElement'+styleSwitch+'.width')
width=parseInt(width)
height=parseInt(height)
if (event.clientX > (document.body.clientWidth - 5 - width))
{
newleft=document.body.clientWidth + document.body.scrollLeft - 5 - width
}
else
{
newleft=document.body.scrollLeft + event.clientX
}
eval('curElement'+styleSwitch+'.pixelLeft=newleft')
if (event.clientY > (document.body.clientHeight - 5 - height))
{
newtop=document.body.clientHeight + document.body.scrollTop - 5 - height
}
else
{
newtop=document.body.scrollTop + event.clientY
}
eval('curElement'+styleSwitch+'.pixelTop=newtop')
}
document.onmousemove = doMouseMove;
</script>

====2、将以下代码加入到HEML的<body></body>之间:

<!-- 以下代码是设定此页的鼠标样式代码 -->
<script language="javascript">
if (navigator.appName == "Netscape") {
}
else
{
document.write('<div ID=OuterDiv>')
document.write('<img ID=iit src="想要显示的图片.gif" STYLE="position:absolute;TOP:5pt;LEFT:5pt;Z-INDEX:10;visibility:hidden;">')
document.write('</div>')
}
</script>
cjfriends 2010-11-16
  • 打赏
  • 举报
回复
谢谢 muheye,谢谢 yhtapmys,在你们的基础上载略加修改就是我要的效果了,感谢所有回帖的兄弟姐妹
cjfriends 2010-11-16
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 tcwsyt 的回复:]
http://topic.csdn.net/u/20100223/17/edb27cb3-24ff-461d-9cff-eb8b8816b6bf.html
[/Quote]

这个我用过,它默认的是click事件,改成mouseover 事件之后不好使,所以来这儿求教了
yhtapmys 2010-11-16
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 cjfriends 的回复:]
谢谢 muheye ,你的代码我看了,很好,但有一点问题,当我的鼠标移动到其中一个div上时,在这个div的左边 弹出层,这个弹出层是固定的,不随鼠标移动。JS很弱,不知如何修改你的代码
[/Quote]


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
.divArr{
width:100px;
height:100px;
background:#CCC;
margin:20px;
}
#divShow{
width:200px;
height:200px;
background:#999;
position:absolute;
display:none;
}
</style>
<script type="text/javascript">
function show(mydiv){
var divShow = document.getElementById('divShow');
divShow.style.top = mydiv.offsetTop + 50 + "px";
divShow.style.left = mydiv.offsetLeft + 50 + "px";

divShow.style.display = "block";
}

function hidden(){
var divShow = document.getElementById('divShow');
divShow.style.display = "none";
}
</script>
</head>
<body>
<div class="divArr" id="div1" onmouseover="show(this)" onmouseout="hidden()">这是第一个DIV</div>
<div class="divArr" id="div1" onmouseover="show(this)" onmouseout="hidden()">这是第二个DIV</div>
<div class="divArr" id="div1" onmouseover="show(this)" onmouseout="hidden()">这是第三个DIV</div>
<div id="divShow">这是浮动的DIV</div>
</body>
</html>
snowwinner 2010-11-16
  • 打赏
  • 举报
回复
最实用的方法:给你那个头像上加个title属性不就可以了
灬上海爽爷 2010-11-16
  • 打赏
  • 举报
回复
http://topic.csdn.net/u/20100223/17/edb27cb3-24ff-461d-9cff-eb8b8816b6bf.html
cjfriends 2010-11-16
  • 打赏
  • 举报
回复
谢谢 muheye ,你的代码我看了,很好,但有一点问题,当我的鼠标移动到其中一个div上时,在这个div的左边 弹出层,这个弹出层是固定的,不随鼠标移动。JS很弱,不知如何修改你的代码
tang871015 2010-11-16
  • 打赏
  • 举报
回复
关键你是要获得当前鼠标移动的位置,在鼠标移动到图像上时则获取该鼠标的位置,并弹出一个div,让这个div的left和top等于你鼠标停留的那个位置
muheye 2010-11-16
  • 打赏
  • 举报
回复
刚做了一尝试,代码如下,希望能给楼主一点启发:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
.divArr{
width:100px;
height:100px;
background:#CCC;
margin:20px;
}
#divShow{
width:200px;
height:200px;
background:#999;
position:absolute;
display:none;
}
</style>
<script type="text/javascript">
function show(event){
var evt = event || window.event;
var divShow = document.getElementById('divShow');
divShow.style.top = evt.clientY + 10 + "px";
divShow.style.left = evt.clientX + 10 + "px";

divShow.style.display = "block";
}
function move(event){
show(event);
}
function hidden(){
var divShow = document.getElementById('divShow');
divShow.style.display = "none";
}
</script>
</head>
<body>
<div class="divArr" id="div1" onmouseover="show(event)" onmousemove="move(event)" onmouseout="hidden()">这是第一个DIV</div>
<div class="divArr" id="div1" onmouseover="show(event)" onmousemove="move(event)" onmouseout="hidden()">这是第二个DIV</div>
<div class="divArr" id="div1" onmouseover="show(event)" onmousemove="move(event)" onmouseout="hidden()">这是第三个DIV</div>
<div id="divShow">这是浮动的DIV</div>
</body>
</html>

87,904

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧