分步思考?
- 需要一个高亮的元素
- 来个遮罩层
- 高亮的上来下
- 获取到要显示元素的内容
代码奉上
<!DOCTYPE html>
<html lang="cn">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
/* 高亮元素盒子 */
.list-box {
margin-top: 60px;
}
/* 高亮元素样式 */
.list-box-item {
list-style: none;
background: paleturquoise;
float: left;
margin: 2px;
padding: 5px;
}
/* 遮罩层 */
.mark {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
overflow: hidden;
outline: 0;
-webkit-overflow-scrolling: touch;
background-color: rgb(0, 0, 0);
filter: alpha(opacity=60);
background-color: rgba(0, 0, 0, 0.3);
z-index: 521;
}
/* 高亮区域 */
.content {
z-index: 1314;
border: 1px dashed #fff;
position: absolute;
}
/* 有意见,把肚子里的吐?出来 */
.tooltip-box {
width: 150px;
height: 26px;
line-height: 26px;
background: white;
position: relative;
-moz-border-radius: 40px;
-webkit-border-radius: 40px;
border-radius: 40px;
padding: 5px 15px;
font-size: 14px;
}
/*加个小尾巴*/
.tooltip-box:before {
content: "";
position: absolute;
right: 100%;
top: -10px;
left: 20%;
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-bottom: 13px solid white;
}
</style>
</head>
<body>
<div class="mark">
<div class="content" id='js-mark-content-id'>
</div>
<div class='tooltip-box' id='js-tooltip-box-id'>
我是新来的一个功能!!!!!
</div>
</div>
</div>
<div class="list-box">
<div class="list-box-item">花自飘零水自流</div>
<div class="list-box-item">一种相思</div>
<div class="list-box-item" id='js-show-id'>两处闲愁</div>
<div class="list-box-item">此情无计可消除</div>
<div class="list-box-item">才下眉头</div>
<div class="list-box-item">却上心头</div>
</div>
</body>
<script>
const show = document.getElementById('js-show-id') // 获取到当前要显示的元素
const showLeft = show.offsetLeft
const showTop = show.offsetTop
const showWidth = show.offsetWidth
const showHeight = show.offsetHeight
//设置一个框
const contentMark = document.getElementById('js-mark-content-id')
contentMark.style.left = showLeft - 3 + 'px'
contentMark.style.top = showTop - 3 + 'px'
const showClone = show.cloneNode(true) // 拷贝所有属性和值。
contentMark.appendChild(showClone)
//设置一个提示语
const tooltipBox = document.getElementById('js-tooltip-box-id')
tooltipBox.style.left = showLeft + 'px'
tooltipBox.style.top = showTop + showHeight + 15 + 'px'
</script>