<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="lib/jquery-3.5.1.js"></script>
<style>
*{
margin: 0;
padding: 0;
}
div{
width: 200px;
height: 100px;
background-color: greenyellow;
position: relative;
margin: 50px;
}
#box p{
width: 300px;
height: 200px;
background-color: aquamarine;
position: absolute;
left: 100px;
top: 100px;
display: none;
/* 鼠标来到这个P标签上也不会触发事件---穿透 */
pointer-events: none;
/* 设置层级 */
z-index: 100;
}
</style>
</head>
<body>
<div id="box">
你的头像
<p>
你的介绍
</p>
</div>
<div>
111111
</div>
<script>
$("#box").mouseover(function(){
$(this).children("p").css("display","block")
})
$("#box").mouseout(function(){
$(this).children("p").css("display","none")
})
$("#box").mousemove(function(evt){
$(this).children("p").offset({//offset基于文档流左上角,要用pageX,pageY
left:evt.pageX,
top:evt.pageY
})
})
</script>
</body>
</html>
结果: