提示框隐藏

Click_Me 2009-06-02 12:13:36

<!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>
<title> new document </title>
<style type="text/css">
#oTip{
width: 120px;
height: 140px;
border: 2px solid #3366FF;
background-color: #FFFEE8;
text-align: center;
display: none;
position: absolute;
font-size: 9pt;
}

#oTip li{
line-height: 20px;
}
</style>
<script type="text/javascript">
<!--

// 添加事件
var addEvent = function(a, b, c, d){
if(a.attachEvent) a.attachEvent(b[0], c);
else a.addEventListener(b[1] || b[0].replace(/^on/,""), c, d || false);
return c;
}

// 取得元素位置
var getPosition = function(el){
var itop = el.offsetTop;
var ileft = el.offsetLeft;
while(el = el.offsetParent){
itop += el.offsetTop;
ileft += el.offsetLeft;
}
return {y: itop, x: ileft};
}

// 加载时绑定mouseover mouseout事件
window.onload = function(){
var oDiv = document.getElementById("oDiv");
addEvent(oDiv, ["onmouseover"], function(e){
showTips(e)
});

addEvent(oDiv, ["onmouseout"], function(e){
disTips(e)
});
}

// 显示Tips
function showTips(e){
var e = e || window.event;
var otarget = e.srcElement || e.target;
var oTip = document.getElementById("oTip");
oTip.style.display = "block";
oTip.style.position = "absolute";
oTip.style.top = (getPosition(otarget).y + 36) + "px";
oTip.style.left = getPosition(otarget).x + "px";
}

// 隐藏Tips
function disTips(e){
var e = e || window.event;
var otarget = e.srcElement || e.target;
var oTip = document.getElementById("oTip");
oTip.style.display = "none";
}
//-->
</script>
</head>

<body>
<div id="oDiv" style="width:40px;height:20px;background-Color:#009900;font-size:9pt;">showTips</div>

<div id="oTip" >
<ul>
<li><a href="http://www.baidu.com"> www.baidu.com </a></li>
<li><a href="http://www.google.com"> www.google.com </a></li>
<li><a href="http://www.sina.com"> www.sina.com </a></li>
<li><a href="http://www.163.com"> www.163.com </a></li>
</ul>
</div>
</body>
</html>



需求:鼠标移到showTips 就显示提示框,移开提示框就隐藏。
问题:但这样导致用户就永远不可能鼠标移入到提示框中进行操作。

我希望的是 鼠标移出showTips但没往提示框上移动就隐藏提示框, 但如果鼠标虽然移出showTips 但是移入了提示框中那样提示框
不隐藏 可以进行超链接操作,这时当鼠标再移出提示框的时候 提示框才隐藏。

自己怎么想都是个矛盾的,不知道是不是设计的有问题,请大家帮忙
...全文
140 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaojing7 2009-06-02
  • 打赏
  • 举报
回复
建议你的提示框和你的showTips 位置坐好控制就好了
你看看CSDN,你头像上面的提示,他是右边的提示和头像之间有紧密的联系的
但是只有上半端再联系着。
monexus 2009-06-02
  • 打赏
  • 举报
回复

var oTipTimer;

// 加载时绑定mouseover mouseout事件
window.onload = function(){
var oDiv = document.getElementById("oDiv");
addEvent(oDiv, ["onmouseover"], function(e){
clearTimeout(oTipTimer);
showTips(e);
});
addEvent(oDiv, ["onmouseout"], function(e){
oTipTimer = setTimeout(function(){
disTips(e);
}, 1000);
});
}
lihan6415151528 2009-06-02
  • 打赏
  • 举报
回复
针对这一种情况,建议把提示框做成一个模拟的,比如用div上面的button来控制,那样会好许多的。。
monexus 2009-06-02
  • 打赏
  • 举报
回复
mouseout时加个setTimeout处理
FanG081020 2009-06-02
  • 打赏
  • 举报
回复
鼠标放到 showTips和 提示框 上都显示提示框,同时 提示框 布局要紧挨着showtips
wtcsy 2009-06-02
  • 打赏
  • 举报
回复
把中间的间隙去掉了
<!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>
<title> new document </title>
<style type="text/css">
#oTip{
width: 120px;
height: 140px;
border: 2px solid #3366FF;
background-color: #FFFEE8;
text-align: center;
display: none;
position: absolute;
font-size: 9pt;
}

#oTip li{
line-height: 20px;
}
</style>
<script type="text/javascript">
<!--

// 添加事件
var addEvent = function(a, b, c, d){
if(a.attachEvent) a.attachEvent(b[0], c);
else a.addEventListener(b[1] || b[0].replace(/^on/,""), c, d || false);
return c;
}

// 取得元素位置
var getPosition = function(el){
var itop = el.offsetTop;
var ileft = el.offsetLeft;
while(el = el.offsetParent){
itop += el.offsetTop;
ileft += el.offsetLeft;
}
return {y: itop, x: ileft};
}

// 加载时绑定mouseover mouseout事件
window.onload = function(){
var oDiv = document.getElementById("oDiv");
var oTip = document.getElementById("oTip");
addEvent(oDiv, ["onmouseover"], function(e){
showTips(e)
});

addEvent(oDiv, ["onmouseout"], function(e){
disTips(e)
});
addEvent(oTip, ["onmouseout"], function(e){
disTips(e)
});
}

// 显示Tips
function showTips(e){
var e = e || window.event;
var otarget = e.srcElement || e.target;
var oTip = document.getElementById("oTip");
oTip.style.display = "block";
oTip.style.position = "absolute";
oTip.style.top = (getPosition(otarget).y + otarget.offsetHeight) + "px";
oTip.style.left = getPosition(otarget).x + "px";
}

// 隐藏Tips
function disTips(e){
var e = e || window.event;
var otarget = e.relatedTarget||e.toElement;
var oTip = document.getElementById("oTip");
if(judge(oTip,otarget))return
oTip.style.display = "none";
}

function judge(parent,child){
if(parent == child) return true;
while(child=child.parentNode){if(child==parent)return true;}
return false;
}
//-->
</script>
</head>

<body>
<div id="oDiv" style="width:40px;height:20px;background-Color:#009900;font-size:9pt;">showTips</div>
<div id="oTip" >
<ul>
<li><a href="http://www.baidu.com"> www.baidu.com </a></li>
<li><a href="http://www.google.com"> www.google.com </a></li>
<li><a href="http://www.sina.com"> www.sina.com </a></li>
<li><a href="http://www.163.com"> www.163.com </a></li>
</ul>
</div>
</body>
</html>
Click_Me 2009-06-02
  • 打赏
  • 举报
回复
Click_Me 2009-06-02
  • 打赏
  • 举报
回复
====================
Click_Me 2009-06-02
  • 打赏
  • 举报
回复
顶下 看看大伙有什么更好的处理方案

87,910

社区成员

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

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