首页 热点专区 义务教育 高等教育 出国留学 考研考公

jq怎样实现鼠标经过隐藏,离开显示div层

发布网友

我来回答

2个回答

热心网友

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
*{margin: 0px;padding: 0px;list-style: none;text-decoration: none}/*通配符,个人习惯*/
.box{width: 100px;height: 100px;}
.box_div{width: 100px;height: 100px;background: #FFFF00}
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-3.2.0.min.js"></script> <!--引用jquery库-->
<script type="text/javascript">
$(function(){
$(".box").mouseover(function(){
$(".box_div").hide();  //隐藏
})
$(".box").mouseout(function(){
$(".box_div").show();  //显示
})
})
//mouseover  当鼠标指针位于元素上方时,会发生 mouseover 事件。
//mouseout   当鼠标指针离开被选元素时,会发生 mouseout 事件。
//hide();    hide() 隐藏
//show();    show() 显示
</script>
</head>
<body>
<div class="box">
<div class="box_div">
我是div
</div>
</div>
</body>
</html>

热心网友

1、jquery中有mouseover(鼠标滑上去触发),mouseout(鼠标离开元素触发)

2、可以这么写

$('#sele').mouseover(function(){//鼠标滑上去
$(this).css({opacity:'0'});//将元素透明度设置为0
})
$('#sele').mouseout(function(){//鼠标离开
$(this).css({opacity:'1'});//将元素透明度设置为1
})

如果是要用display的话,可以将鼠标滑上去和离开事件绑定到包含要操作的div的元素来控制,因为如果display:none的话,找不到这个dom元素,也就不存在mouseover和mouseout事件了

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com