-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpointer.js
More file actions
76 lines (65 loc) · 2.15 KB
/
Copy pathpointer.js
File metadata and controls
76 lines (65 loc) · 2.15 KB
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
/*
pointer.js was created by OwL for use on websites,
and can be found at https://seattleowl.com/pointer.
*/
const pointer = document.createElement("div")
pointer.id = "pointer-dot"
const ring = document.createElement("div")
ring.id = "pointer-ring"
document.body.insertBefore(pointer, document.body.children[0])
document.body.insertBefore(ring, document.body.children[0])
let mouseX = -100
let mouseY = -100
let ringX = -100
let ringY = -100
let isHover = false
let mouseDown = false
const init_pointer = (options) => {
window.onmousemove = (mouse) => {
mouseX = mouse.clientX
mouseY = mouse.clientY
}
window.onmousedown = (mouse) => {
mouseDown = true
}
window.onmouseup = (mouse) => {
mouseDown = false
}
const trace = (a, b, n) => {
return (1 - n) * a + n * b;
}
window["trace"] = trace
const getOption = (option) => {
let defaultObj = {
pointerColor: "#4CAF50",
ringSize: 15,
ringClickSize: (options["ringSize"] || 15) - 5,
}
if (options[option] == undefined) {
return defaultObj[option]
} else {
return options[option]
}
}
const render = () => {
ringX = trace(ringX, mouseX, 0.2)
ringY = trace(ringY, mouseY, 0.2)
if (document.querySelector(".p-action-click:hover")) {
pointer.style.borderColor = getOption("pointerColor")
isHover = true
} else {
pointer.style.borderColor = "white"
isHover = false
}
ring.style.borderColor = getOption("pointerColor")
if (mouseDown) {
ring.style.padding = getOption("ringClickSize") + "px"
} else {
ring.style.padding = getOption("ringSize") + "px"
}
pointer.style.transform = `translate(${mouseX}px, ${mouseY}px)`
ring.style.transform = `translate(${ringX - (mouseDown ? getOption("ringClickSize") : getOption("ringSize"))}px, ${ringY - (mouseDown ? getOption("ringClickSize") : getOption("ringSize"))}px)`
requestAnimationFrame(render)
}
requestAnimationFrame(render)
}