-
Notifications
You must be signed in to change notification settings - Fork 1
/
blocks3.js
54 lines (54 loc) · 1.68 KB
/
blocks3.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
//请使用cube.css!!否则脚本运行无效
const cube3d = {};
{
cube3d.gen = function () {
let main = document.createElement("div");
let faces = {};//记录每个面
main.className = "cube3d";
"front back left right top bottom".split(" ").forEach((e) => {
let div = document.createElement("div");
div.setAttribute(e, "");
faces[e] = div;
main.appendChild(div);
});
main.faceStyles = new Proxy({}, {
get: function (tar, name) {
return main.firstChild.style[name];
},
set: function (tar, name, val) {
[...main.children].forEach((e) => {
e.style[name] = val;
});
}
});
main.setvar = function (prop, val) {
if (typeof prop != "object" && val) {
main.style.setProperty(String("--" + prop), val);
} else {
for (let i in prop) {
main.style.setProperty(String("--" + i), prop[i]);
}
}
};
main.getvar = function (prop) {
let one = false;
let arr = [];
if (!prop instanceof Array) {
prop = [prop];
one = true;
}
prop.forEach((e) => {
arr.push(main.style.getPropertyValue("--" + e));
});
return one ? arr[0] : arr;
};
Object.defineProperties(main, {
faces: {
get: function () {
return Object.assign({}, faces);
}
}
});
return main;
};
}