下面是代码
我希望的是 鼠标离开红色的 div的 时候
div不是立刻消失 而是1秒后在消失
如果在1秒内回道了红色div的范围 就不消失.........
<!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=gb2312" />
<title></title>
<style type="text/css"></style> <body >
<div id='div' style="height:100px; width:100px; border:1px solid #cccccc;background-color:#cccccc"></div>
<div id='tip' style="height:200px; width:200px; border:1px solid #cccccc;background-color:#FF0000;position:absolute;display:none"></div>
<script type="text/javascript">
var $ = function(id){return document.getElementById(id)}
window.onload = function(){
$('div').onmouseover = function(){$('tip').style.display = "block"}
$('div').onmouseout = function(e){
e = window.event || e;
var obj = e.relatedTarget||e.toElement;
if(obj == $('tip'))return;
$('tip').style.display = "none"
}
$('tip').onmouseout=function(){$('tip').style.display = "none"}
}
</script>
</body>
</html>
我希望的是 鼠标离开红色的 div的 时候
div不是立刻消失 而是1秒后在消失
如果在1秒内回道了红色div的范围 就不消失.........
<!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=gb2312" />
<title></title>
<style type="text/css"></style> <body >
<div id='div' style="height:100px; width:100px; border:1px solid #cccccc;background-color:#cccccc"></div>
<div id='tip' style="height:200px; width:200px; border:1px solid #cccccc;background-color:#FF0000;position:absolute;display:none"></div>
<script type="text/javascript">
var $ = function(id){return document.getElementById(id)}
window.onload = function(){
$('div').onmouseover = function(){$('tip').style.display = "block"}
$('div').onmouseout = function(e){
e = window.event || e;
var obj = e.relatedTarget||e.toElement;
if(obj == $('tip'))return;
$('tip').style.display = "none"
}
$('tip').onmouseout=function(){$('tip').style.display = "none"}
}
</script>
</body>
</html>
解决方案 »
- 请教个有关垃圾回收机制的问题
- 让自己画的小人动起来
- 淘宝UED
- 如何读取并清除某指定的Cookie?
- 请各位高手,帮我看一下这个代码错在那里啊?我找了很久也找不到啊。谢谢!
- 如何知道URL传了什么参数过来?
- win media player 10在IE中能显示出来,在firefox2.0却提示安装插件,这是为什么?
- 能不能控制「IE 页面是否可以打印」﹖
- 请教阿信等高手:如何将fason(阿信)的CSDN无限级树数据库版(ASP+ACCESS)改为仿xp版的
- 这个怎样解决:页面左面有一个树形菜单,可以隐藏,隐藏后右面内容占据整个页面,把banner条都隐藏了,怎么解决呢?
- addEventListener问题
- setinterval
setTimeOut(function(){
e = window.event || e;
var obj = e.relatedTarget||e.toElement;
if(obj == $('tip'))return;
$('tip').style.display = "none"
},1000)
}
var $ = function(id){return document.getElementById(id)}window.onload = function(){
var _OK = true;
$('div').onmouseover = function()
{
$('tip').style.display = "block";
}
$('div').onmouseout = function(e){
e = window.event || e;
var obj = e.relatedTarget||e.toElement;
if(obj == $('tip'))return;
$('tip').style.display = "none"
}
$('tip').onmouseout=function(){
_OK = true;
setTimeout(function (){
if (_OK) { $('tip').style.display = "none"; }
}, 1000);
}
$('tip').onmouseover=function(){ _OK = false; }
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
<style type="text/css"></style> <body >
<div id='div' style="height:100px; width:100px; border:1px solid #cccccc;background-color:#cccccc"></div>
<div id='tip' style="height:200px; width:200px; border:1px solid #cccccc;background-color:#FF0000;position:absolute;display:none"></div>
<script type="text/javascript">
var $ = function(id){return document.getElementById(id)}
window.onload = function(){
var myTime="";
$('div').onmouseover = function(){
$('tip').style.display = "block"
if(myTime!="") clearTimeout(myTime);
}
$('div').onmouseout = function(e){
myTime=setTimeout(function(){$('tip').style.display = "none"},1000)
}
$('tip').onmouseout=function(){$('tip').style.display = "none"}
}
</script>
</body>
</html>
setimemout不是写在
myTime=setTimeout(function(){$('tip').style.display = "none"},1000)而是写在函数上的 如: setTimeout(function(){},1000)肯定要一个变量去当记时器 如 time = setTimeout(function(){},1000)当离开红色的div 移动到灰色的地方的时候 红色的div应该还是显示的