-
Notifications
You must be signed in to change notification settings - Fork 26
/
区块停留计数Date实现.html
82 lines (81 loc) · 2.43 KB
/
区块停留计数Date实现.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
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset=utf-8>
<title>timeCounter</title>
</head>
<style>
.mod-spm[data-spmid='123']{
width: 100px;
height: 100px;
margin-right: auto;
margin-left: auto;
margin-bottom: 20px;
background-color: #fff;
border: 2px #000 solid;
}
.mod-spm[data-spmid='456']{
width: 100px;
height: 100px;
margin-right: auto;
margin-left: auto;
margin-bottom: 20px;
background-color: #fff;
border: 2px #000 solid;
}
.mod-spm[data-spmid='789']{
width: 100px;
height: 100px;
margin-right: auto;
margin-left: auto;
margin-bottom: 20px;
background-color: #fff;
border: 2px #000 solid;
}
</style>
<body>
<div class="mod-spm" data-spmid="123">
<div class="child_a"></div>
<div class="child_b"></div>
<div class="child_c"></div>
<div class="child_d"></div>
</div>
<div class="mod-spm" data-spmid="456">
<div class="child_a"></div>
<div class="child_b"></div>
<div class="child_c"></div>
<div class="child_d"></div>
</div>
<div class="mod-spm" data-spmid="789">
<div class="child_a"></div>
<div class="child_b"></div>
<div class="child_c"></div>
<div class="child_d"></div>
</div>
<script type="text/javascript">
var startTime = 0,
totalTime = 0,
stayTime = 0,
counter1 = 0,
counter2 = 0,
counter3 = 0;
var timer = null;
function timerCounter(div,startTime,totalTime,num){
var span = document.createElement('span');
div.addEventListener('mouseover',function(){
startTime = new Date().getTime();
},false);
div.addEventListener('mouseout',function(){
totalTime += new Date().getTime()-startTime;
//console.log(totalTime);
span.innerHTML = '鼠标离开后才会显示停留时长,stay:'+Math.floor(totalTime/1000);
},false);
div.appendChild(span);
}
var div = document.getElementsByClassName('mod-spm');
timerCounter(div[0],startTime,totalTime,div[0].dataset['spmid']);
timerCounter(div[1],startTime,totalTime,div[1].dataset['spmid']);
timerCounter(div[2],startTime,totalTime,div[2].dataset['spmid']);
</script>
</body>
</html>