-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hello14.html
83 lines (83 loc) · 2.29 KB
/
Hello14.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style type="text/css">
.tooltip{
position: relative;
}
.tooltip span{
width: 180px;
padding: 5px 10px;
color: #FFFFFF;
background: #000000;
text-align: center;
border-radius: 2px;
position: absolute;
left: -90px;
top: -40px;
opacity: 0;
visibility: hidden;
transition: opacity .5s;
}
.tooltip span::after{
content: "";
width: 0;
height: 0;
position: absolute;
top: 100%;
left: 50%;
margin-left: -8px;
border-top: 8px solid black;
border-right: 8px solid transparent;
border-left: 8px solid transparent;
}
.tooltip span.show{
opacity: 1;
visibility: visible;
}
p,h2{
text-align: center;
}
</style>
</head>
<body>
<div class="container">
<h2>tooltip提示框</h2>
<p><a href="#" class="tooltip" data-content="积件思维">组件</a></p>
<p><a href="#" class="tooltip" >上</a> 、、、、
<a href="#" class="tooltip" data-content="下">下</a>、、、、
<a href="#" class="tooltip" data-content="左">左</a>、、、、
<a href="#" class="tooltip" data-content="右">右</a>
</p>
</div>
<script type="text/javascript">
var tips =document.querySelectorAll('.tooltip');
if(tips.length==0){
console.log("没有提示");
}else{
for(var i=0;i<tips.length;i++){
var content = document.createElement('span');
var date = tips[i].hasAttribute('data-content')?tips[i].getAttribute('data-content'):'提示为空';
content.innerHTML = date;
tips[i].appendChild(content);
tips[i].addEventListener("mouseover",mouseoverHandler);
tips[i].addEventListener("mouseout",mouseoutHandler);
}
}
function mouseoverHandler(){
var event = event||window.event;
var target = event.target||event.srcElement;
var targetSpan = target.getElementsByTagName('span')[0];
targetSpan.classList.add('show');
}
function mouseoutHandler(){
var event = event||window.event;
var target = event.target||event.srcElement;
var targetSpan = target.getElementsByTagName('span')[0];
targetSpan.classList.remove('show');
}
</script>
</body>
</html>