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

 我来答
小迪1995
2017-10-16 · TA获得超过474个赞
知道答主
回答量:235
采纳率:50%
帮助的人:47.5万
展开全部
<!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>
唯美丶浅歌殇丿
2017-10-16 · 超过69用户采纳过TA的回答
知道小有建树答主
回答量:90
采纳率:90%
帮助的人:94.4万
展开全部

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事件了

本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式