-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
118 lines (112 loc) · 3.43 KB
/
script.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
function readURL(input) {
if (input.files && input.files[0]) {
let reader = new FileReader();
reader.onload = function (e) {
let listIcon = e.target.result;
let image = new Image();
image.src = listIcon;
image.onload = function () {
adjustIcons(this.height);
};
document.getElementById("list-image").src = listIcon;
document.getElementById(
"myList"
).style.listStyleImage = `url(${e.target.result})`;
document
.querySelector(".image-upload-wrap")
.classList.remove("image-dropping");
};
reader.readAsDataURL(input.files[0]);
}
}
let dragTimer;
document.addEventListener("dragstart", function (e) {
e.dataTransfer.setData("image", e.target.id);
});
document.addEventListener("dragover", function (e) {
e.preventDefault();
let dt = e.dataTransfer;
if (
dt.types &&
(dt.types.indexOf
? dt.types.indexOf("Files") != -1
: dt.types.contains("Files"))
) {
document
.querySelector(".image-upload-wrap")
.classList.add("image-dropping");
window.clearTimeout(dragTimer);
}
});
document.addEventListener("dragleave", function (e) {
e.preventDefault();
dragTimer = window.setTimeout(function () {
document
.querySelector(".image-upload-wrap")
.classList.remove("image-dropping");
}, 25);
});
let adjuster = document.querySelectorAll(".adjuster");
let fontSizeOfList;
let up = document.querySelector(".up");
let down = document.querySelector(".down");
let iconImage = document.getElementById("list-image");
let algorithm = document.querySelector(".algorithm");
let count = 0;
let fontSizeInput = document.getElementById("font-size");
function adjustIcons(iconHeight) {
let el = document.querySelector("li");
fontSizeOfList =
fontSizeInput.value ||
parseFloat(window.getComputedStyle(el, null).getPropertyValue("font-size"));
adjuster.forEach(
(icon) => (icon.style.top = `${-iconHeight / 2 + fontSizeOfList / 4}px`)
);
// console.log(`${-iconHeight / 2 + fontSizeOfList / 4}px`);
codeOutput(
`${-iconHeight / 2 + fontSizeOfList / 4}`,
iconHeight,
fontSizeOfList,
0
);
}
up.addEventListener("click", () => {
adjuster.forEach(
(icon) => (icon.style.top = parseInt(icon.style.top) - 1 + "px")
);
count -= 1;
codeOutput(
parseInt(adjuster[0].style.top),
iconImage.height,
fontSizeOfList,
count
);
});
down.addEventListener("click", () => {
adjuster.forEach(
(icon) => (icon.style.top = parseInt(icon.style.top) + 1 + "px")
);
count += 1;
codeOutput(
parseInt(adjuster[0].style.top),
iconImage.height,
fontSizeOfList,
count
);
});
fontSizeInput.addEventListener("input", () => {
fontSizeOfList = fontSizeInput.value || "16";
adjuster.forEach((icon) => (icon.style.fontSize = fontSizeOfList + "px"));
adjustIcons(iconImage.height);
});
function codeOutput(topValue, iconHeight, fontSizeOfList = 16, count) {
document.querySelector(".tick").style.display = "none";
document.querySelector(".clipboard").classList.remove("clipboard2");
console.log(
`The algorithm is: ${fontSizeOfList}/4 [fontsize/4] - ${iconHeight}/2 [listicon/2] + (${count}) [±error] = ${topValue}px`
);
algorithm.textContent = `The algorithm is: ${fontSizeOfList}/4 [fontsize/4] - ${iconHeight}/2 [listicon/2] + (${count}) [±error] = ${topValue}px`;
document.querySelectorAll(
".color3"
)[2].textContent = `top:${topValue}px; position:relative`;
}