-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspriteLibrary.js
More file actions
28 lines (28 loc) · 1.35 KB
/
spriteLibrary.js
File metadata and controls
28 lines (28 loc) · 1.35 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
function Sprite(elementType, relativeCoords, pxCoords, percentCoords, parent, style, inner, size) {
let elem = document.createElement(elementType);
elem.style = style;
elem.style.width = size[0] + "px";
elem.style.height = size[1] + "px";
elem.style.position = "absolute";
elem.style.transform = "translate(" + (relativeCoords[0] - 50) + "%," + (relativeCoords[1] + 50) + "%)";
elem.style.left = "calc(" + pxCoords[0] + "px + " + (50 + percentCoords[0]) + "%)";
elem.style.bottom = "calc(" + pxCoords[1] + "px + " + (50 + percentCoords[1]) + "%)";
elem.innerHTML = inner;
parent.append(elem);
this.elem = elem;
this.getPos = function () {
return [relativeCoords, pxCoords, percentCoords];
};
this.setRelativeCoords = function (pos) {
this.elem.style.transform = "translate(" + (pos[0] + 50) + "%," + (pos[1] + 50) + "%)"
};
this.setPxCoords = function (pos) {
this.elem.style.left = "calc(" + pos[0] + "px + " + (50 + percentCoords[0]) + "%)";
this.elem.style.bottom = "calc(" + pos[1] + "px + " + (50 + percentCoords[1]) + "%)";
};
this.setPercentCoords = function (pos) {
this.elem.style.left = "calc(" + pxCoords[0] + "px + " + (50 + pos[0]) + "%)";
this.elem.style.bottom = "calc(" + pxCoords[1] + "px + " + (50 + pos[1]) + "%)";
};
this.localVars = {};
}