-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhover.js
More file actions
48 lines (48 loc) · 1.14 KB
/
hover.js
File metadata and controls
48 lines (48 loc) · 1.14 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
const hover = (() => {
let e, x, y;
function update() {
if (!e) return;
e.css({
// move to left if at the edge of screen
left: x + e.width() + 15 < $(window).width() ? x + 15 : x - e.width() - 10,
// Try to lock to the bottom
top: y + e.height() + 18 > $(window).height() ? $(window).height() - e.height() : y + 18,
});
}
eventManager.on("jQuery", () => {
$(document).on("mousemove.script", function mouseMove(event) {
x = event.pageX - window.pageXOffset;
y = event.pageY - window.pageYOffset;
update();
});
});
function hide() {
if (e) {
// Hide element
e.remove();
e = null;
}
}
function show(data, border = null) {
return function hoverAction(event) {
hide();
if (event.type === 'mouseleave') return;
e = $("<div>");
e.append(data);
e.append($(footer).clone());
e.css({
border,
position: "fixed",
"background-color": "rgba(0,0,0,0.9)",
padding: '2px',
'z-index': 1220,
});
$("body").append(e);
update();
};
}
return {
hide,
show,
};
})();