js:鼠标移动到文字显示div,移出文字div显示,鼠标能移进div


<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>DIV弹出层</title>
<link rel="stylesheet" type="text/css" href="bootstrap.min.css">
</head>
<body style="margin: 50px 0 0 50px">

<div id="title1">
<a>hover</a>
</div>
<div id="hiddenDiv" style="display:none">
<div class="btn-group" role="group" aria-label="...">
<button type="button" class="btn btn-default" onclick="button1()">Left</button>
<button type="button" class="btn btn-default" onclick="button2()">Middle</button>
<button type="button" class="btn btn-default" onclick="button3()">Right</button>
</div>
</div>

<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="bootstrap.min.js"></script>
<script>
var title = document.getElementById('title1');
var hiddenDiv = document.getElementById('hiddenDiv');
var timer = null;
hiddenDiv.onmouseover = title.onmouseover = function(){
if(timer) clearTimeout(timer)
hiddenDiv.style.display = 'block';
}
hiddenDiv.onmouseout = title.onmouseout = function(){
timer = setTimeout(function(){
hiddenDiv.style.display = 'none';
},400);
}
function button1(){
alert(1);
}
function button2(){
alert(2);
}
function button3(){
alert(3);
}
</script>
</body>
</html>

posted @ 2017-11-29 10:25  明烟雨任  阅读(1160)  评论(0编辑  收藏  举报