-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDaDKeyboard.js
39 lines (30 loc) · 885 Bytes
/
DaDKeyboard.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
keyboard_move.ondragstart = function() {
return false;
};
keyboard_move.onmousedown = function(e) {
let coords = getCoords(keyboard);
let shiftX = e.pageX - coords.left;
let shiftY = e.pageY - coords.top;
keyboard.style.position = 'absolute';
moveAt(e);
document.body.appendChild(keyboard);
keyboard.style.zIndex = 1000;
function moveAt(e) {
keyboard.style.left = e.pageX - shiftX + 'px';
keyboard.style.top = e.pageY - shiftY + 'px';
}
document.onmousemove = function(e) {
moveAt(e);
}
keyboard.onmouseup = function() {
document.onmousemove = null;
keyboard.onmouseup = null;
}
}
function getCoords(elem) { // кроме IE8-
var box = elem.getBoundingClientRect();
return {
top: box.top + pageYOffset,
left: box.left + pageXOffset
};
}