<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.box{width: 300px;height: 40px;background: #ccc;margin: 20px auto;position: relative;}
.box *{margin: 0;}
.box h2{line-height: 40px;}
.box p{width: 200px;background: #eee;font-size: 14px;position: absolute;left:0;top:0;display: none;z-index: 1;}
#box{width: 100px;height: 100px;background: red;display: block}
#box:hover{display: none;}
</style>
</head>
<body>
<div class="box">
<h2>这是一个标题1</h2>
<p>这是标题1对应的详细文本这是标题1对应的详细文本这是标题1
对应的详细文本这是标题1对应的详细文本这是标题1
对应的详细文本这是标题1对应的详细文本这是标题1</p>
</div>
<div class="box">
<h2>这是一个标题2</h2>
<p>这是标题2对应的详细文本题2对应的详细文本题2对应的详细文本题2
对应的详细文本题2对应的详细文本题2对应的详细文本题2
对应的详细文本题2对应的详细文本题2</p>
</div>
<div id="box"></div>
</body>
<script>
var ah2 = document.querySelectorAll(".box h2");
for(var i=0;i<ah2.length;i++){
ah2[i].onmouseover = function(){
// console.log(this);
this.nextElementSibling.style.display = "block";
}
ah2[i].onmousemove = function(eve){
// console.log(this);
var e = eve || window.event;
// 将h2后面的p的定位位置,设置成鼠标的坐标,稍微往后一点,防止阻挡鼠标放在事件源身上
this.nextElementSibling.style.left = e.offsetX + 5 + "px";
this.nextElementSibling.style.top = e.offsetY + 5 + "px";
}
ah2[i].onmouseout = function(){
// console.log(this);
this.nextElementSibling.style.display = "none";
}
}
</script>
</html>
js实现跟随鼠标移动的提示框
最新推荐文章于 2023-03-09 20:43:42 发布
本文介绍如何利用JavaScript、CSS和HTML创建一个跟随鼠标移动的提示框。通过监听鼠标移动事件,动态更新提示框的位置,并展示相应的内容,为用户提供实时反馈。
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
AutoGPT
AI应用
AutoGPT于2023年3月30日由游戏公司Significant Gravitas Ltd.的创始人Toran Bruce Richards发布,AutoGPT是一个AI agent(智能体),也是开源的应用程序,结合了GPT-4和GPT-3.5技术,给定自然语言的目标,它将尝试通过将其分解成子任务,并在自动循环中使用互联网和其他工具来实现这一目标
1712

被折叠的 条评论
为什么被折叠?



