-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
147 lines (118 loc) · 4.83 KB
/
index.html
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<!DOCTYPE html>
<html lang="en" style="height: 100%;">
<head>
<meta charset="UTF-8" />
<title>Edificio Mirador</title>
<style>
body {
margin: 0;
padding: 0;
box-sizing: border-box;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
background-color: #202020;
}
#info {
position: absolute;
display: inline-block;
text-align: center;
width: auto;
background-color: white;
top: 50px;
left: 50px;
z-index: 1;
padding: 5px;
border-radius: 5px;
}
#image {
width: 100%;
}
#selector {
width: 0px;
height: 0px;
box-sizing: border-box;
position: absolute;
top: 30px;
left: 30px;
}
</style>
<script type="application/javascript">
const horizontalGrids = 42;
const verticalGrids = 22;
const minHorizontalIndex = 0;
const maxHorizontalIndex = 41;
const minVerticalIndex = 0;
const maxVerticalIndex = 21;
const fillAxisArray = (min, max, isChars = false) => {
const axisArray = [];
for (let i = max; i >= min; i--) {
axisArray.push(isChars ? String.fromCharCode(i) : i);
}
return axisArray;
}
const horizontalGrid = fillAxisArray(0, 41);
const verticalGrid = fillAxisArray(64, 85, true);
document.addEventListener("DOMContentLoaded", function (event) {
const img = document.getElementById("image");
const info = document.getElementById("info");
const selector = document.getElementById("selector");
selector.addEventListener("mousemove", (e) => {
const mouseX = e.clientX;
const mouseY = e.clientY;
info.style.left = `${mouseX + 10}px`;
info.style.top = `${mouseY + 25}px`;
});
img.addEventListener("mousemove", (e) => {
const mouseX = e.clientX;
const mouseY = e.clientY;
const imgBound = img.getBoundingClientRect();
const imgLeft = imgBound.left;
const imgTop = imgBound.top;
const xAdjusted = mouseX - imgLeft;
const yAdjusted = mouseY - imgTop;
const imgWidth = imgBound.width;
const imgHeight = imgBound.height;
const pixelsXPerGrid = imgWidth / horizontalGrids;
const pixelsYPerGrid = imgHeight / verticalGrids;
const x = Math.floor(xAdjusted / pixelsXPerGrid);
const y = Math.floor(yAdjusted / pixelsYPerGrid);
info.style.left = `${mouseX + 10}px`;
info.style.top = `${mouseY + 20}px`;
if (x > minHorizontalIndex && x < maxHorizontalIndex && y > minVerticalIndex && y < maxVerticalIndex) {
info.innerHTML = `[${verticalGrid[y]}, ${horizontalGrid[x]}]`;
info.style.transform = "translateX(-50%)";
info.style.padding = "5px";
selector.style.width = `${pixelsXPerGrid}px`;
selector.style.height = `${pixelsYPerGrid}px`;
selector.style["box-shadow"] = "inset 0px 0px 0px 2px #fff";
selector.style.top = `${y * pixelsYPerGrid + imgTop}px`;
selector.style.left = `${x * pixelsXPerGrid + imgLeft}px`;
selector.style.cursor = 'pointer';
const letterToIndex = (20 - y);
const numberToIndex = (41 - x)
const tokenId = Number.parseInt(verticalGrid[y].charCodeAt(0)) % 2 !== 0
? letterToIndex * 40 + numberToIndex
: letterToIndex * 40 + (40 - numberToIndex) + 1;
selector.href = `https://opensea.io/assets/matic/0xb11ecd7c193a764403914e0ecd963e622e02deb6/${tokenId}`
} else {
info.innerHTML = "";
info.style.padding = "0px";
selector.style.width = `0px`;
selector.style.height = `0px`;
selector.style["box-shadow"] = "none";
}
});
});
</script>
</head>
<body>
<div id="info">
</div>
<div style="width: 80%;">
<img id="image" src="Art_Guides_72pp.png" alt="edificio mirador" />
</div>
<a id="selector" target="_blank"></a>
</body>
</html>