js 鼠标移入div,右边显示子div,当鼠标移除时子div消失,但是当鼠标移到子div上,子div不消失
2个回答
展开全部
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>show/hide</title>
<style>
html,body{margin:0;padding:0;width:100%;background:#ededed;}
#main{width:400px;height:300px;margin:200px auto;border:1px solid #ccc;padding-top:20px;}
#subDiv{width:200px;height:150px;margin:75px auto;border:1px solid #ff0000;;display:none;text-align:center;line-height:150px;}
</style>
<script src="http://apps.bdimg.com/libs/jquery/1.7.2/jquery.min.js"></script>
</head>
<body>
<div id="main">
<div id="subDiv">sub div</div>
</div>
<script>
$(function(){
$('#main').on('mouseover', function(){
$('#subDiv').show();
}).on('mouseleave', function(){
$('#subDiv').hide();
if(!$(this).data("events")['mouseover']){
$(this).on('mouseover', function(){$('#subDiv').show();});
}
});
$('#subDiv').on('mouseover', function(){
$('#main').off('mouseover');
$('#subDiv').hide();
});
});
</script>
</body>
</html>
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
var title = document.getElementById('sort_dilog');
var hiddenDiv = document.getElementById('dilog_div');
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);
}
var hiddenDiv = document.getElementById('dilog_div');
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);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询