-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmoveControls.js
More file actions
32 lines (27 loc) · 1.21 KB
/
moveControls.js
File metadata and controls
32 lines (27 loc) · 1.21 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
window.addEventListener("load", function () {
const boxElement = document.getElementById("meet-controls-bar");
const draggable = document.getElementById("draggable");
document.addEventListener("mousedown", function (event) {
if (event.target === draggable) {
draggable.style.cursor = "grabbing";
const offsetX = boxElement.offsetLeft;
const offsetY = boxElement.offsetTop;
const initialX = event.clientX - offsetX;
const initialY = event.clientY - offsetY;
const mouseMoveHandler = function (event) {
// limit the movement of the box within the screen
const maxX = window.innerWidth - boxElement.offsetWidth;
const maxY = window.innerHeight - boxElement.offsetHeight;
const x = Math.min(maxX, Math.max(0, event.clientX - initialX));
const y = Math.min(maxY, Math.max(0, event.clientY - initialY));
boxElement.style.left = x + "px";
boxElement.style.top = y + "px";
};
document.addEventListener("mousemove", mouseMoveHandler);
document.addEventListener("mouseup", function () {
draggable.style.cursor = "grab";
document.removeEventListener("mousemove", mouseMoveHandler);
});
}
});
});