-
Notifications
You must be signed in to change notification settings - Fork 0
/
round.js
55 lines (50 loc) · 1.64 KB
/
round.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
let pointerId = "mouse-pointer";
//Add pointer element to DOM
const initRound = (ptr = "mouse-pointer") => {
if (document.getElementById(ptr) === null) {
console.log("init called ", ptr);
pointerId = ptr;
const mousePointer = document.createElement("div");
mousePointer.setAttribute("id", ptr);
document.body.appendChild(mousePointer);
}
};
const movePointerRound = ({
color = "white",
width = "3.5rem",
height = "3.5rem",
transition = "0.1s",
transitionDuration = "100ms",
mixBlendMode = "difference",
zIndex = 100,
borderRadius = "9999px",
leftOffset = 30,
topOffset = 30,
}) => {
if (document.getElementById(pointerId) !== null) {
console.log("move called ", color, width, height);
const pointerStyle = document.getElementById(pointerId).style;
//Add css
pointerStyle.backgroundColor = color;
pointerStyle.width = width;
pointerStyle.height = height;
pointerStyle.transitionDuration = transitionDuration;
pointerStyle.mixBlendMode = mixBlendMode;
pointerStyle.zIndex = zIndex;
pointerStyle.borderRadius = borderRadius;
pointerStyle.position = "absolute";
pointerStyle.pointerEvents = "none";
//Handle mouse events
document.addEventListener("mousemove", (event) => {
pointerStyle.transition = transition;
pointerStyle.transform = "scale(1)";
pointerStyle.left = `${event.pageX - leftOffset}px`;
pointerStyle.top = `${event.pageY - topOffset}px`;
});
document.addEventListener("mouseleave", () => {
pointerStyle.transition = transition;
pointerStyle.transform = "scale(0)";
});
}
};
export { initRound, movePointerRound };