-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinfo.js
41 lines (37 loc) · 1.13 KB
/
info.js
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
"use strict"
var infodiv
$(function(){
var $info = $(".info")
if ($info.length > 0) infodiv = $info[0]
else {
var main = $("#main")[0]
infodiv = document.createElement("div")
infodiv.className = "info"
main.insertBefore(infodiv, main.children[0])
}
})
// Example: showInfo(event, "阿芙杖", ["攻击+19", "暴击+7%", "吸血3%"])
// or showInfo(event, "阿芙杖", "攻击+19\n暴击+7%\n吸血3%")
// position should contain pageX and pageY
function showInfo(position, title, detail) {
if (detail instanceof Array) {
detail = detail.join("\n")
}
var name = document.createElement("span")
name.className = "name"
name.innerText = title
var br = document.createElement("br")
var details = document.createElement("span")
details.className = "detail"
details.innerText = detail
infodiv.innerHTML = ""
infodiv.appendChild(name)
infodiv.appendChild(br)
infodiv.appendChild(details)
infodiv.style.display = "inline-block"
infodiv.style.left = (position.pageX - infodiv.clientWidth / 2) + "px"
infodiv.style.top = (position.pageY - infodiv.clientHeight - 50) + "px"
}
function hideInfo() {
infodiv.style.display = "none"
}