-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
182 lines (168 loc) · 6.81 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
<script src="https://cdn.tailwindcss.com"></script>
<style type="text/tailwindcss">
@import url("https://fonts.googleapis.com/css?family=Inter:100,200,300,400,500,600,700,800,900&display=swap");
html,
body {
height: 100%;
width: 100%;
@apply bg-white;
font-family: "Inter", sans-serif;
margin: 0;
overflow: hidden; /* Hide scrollbars */
}
.grid,
.grid2,
.grid3,
.grid4 {
display: grid;
grid-template-columns: repeat(100, 60px); /* Updated to 50px */
grid-template-rows: repeat(50, 60px); /* Updated to 50px */
gap: 1px; /* Adjust gap as needed */
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none; /* Allow mouse events to go through the grid */
}
.grid img,
.grid2 img,
.grid3 img,
.grid4 img {
width: 100%;
height: 100%;
object-fit: cover;
}
</style>
</head>
<body>
<div class="body-holder h-full w-full flex items-center justify-center">
<button
class="gridclick bg-blue-100 hover:bg-blue-200 text-neutral-600 py-1 px-5 text-sm rounded-lg"
style="transition: 0.3s ease"
onclick="generateGrids()"
>
Click 20 times for surpise.
</button>
</div>
<div class="grid"></div>
<div class="grid2"></div>
<div class="grid3"></div>
<div class="grid4"></div>
<script>
function generateGrids() {
document.querySelector(".gridclick").attributes.disabled = true;
document.querySelector(".gridclick").style.cursor = "none";
document.body.style.cursor = "none";
const grid = document.querySelector(".grid");
const grid2 = document.querySelector(".grid2");
const grid3 = document.querySelector(".grid3");
const grid4 = document.querySelector(".grid4");
const gridSize = 60; // Updated size of each grid cell
const resetThreshold = gridSize; // Updated threshold for resetting the grid position
// Clear existing grids
grid.innerHTML = "";
grid2.innerHTML = "";
grid3.innerHTML = "";
grid4.innerHTML = "";
// Create grid cells with images for grid
for (let i = 0; i < 100; i++) {
for (let j = 0; j < 50; j++) {
const cell = document.createElement("div");
cell.classList.add("grid-cell");
cell.style.width = `${gridSize}px`;
cell.style.height = `${gridSize}px`;
cell.style.backgroundSize = `auto 20px`;
cell.style.backgroundRepeat = `no-repeat`;
cell.style.backgroundPosition = `center center`;
cell.style.backgroundImage =
"url('https://www.freeiconspng.com/thumbs/cursor-png/white-mouse-cursor-arrow-by-qubodup-11.png')";
grid.appendChild(cell);
}
}
// Create grid cells with images for grid2
for (let i = 0; i < 100; i++) {
for (let j = 0; j < 50; j++) {
const cell = document.createElement("div");
cell.classList.add("grid-cell");
cell.style.width = `${gridSize}px`;
cell.style.height = `${gridSize}px`;
cell.style.backgroundSize = `auto 20px`;
cell.style.backgroundRepeat = `no-repeat`;
cell.style.backgroundPosition = `center center`;
cell.style.backgroundImage =
"url('https://www.freeiconspng.com/thumbs/cursor-png/white-mouse-cursor-arrow-by-qubodup-11.png')";
grid2.appendChild(cell);
}
}
// Create grid cells with images for grid3 (only x-direction)
for (let i = 0; i < 100; i++) {
for (let j = 0; j < 50; j++) {
const cell = document.createElement("div");
cell.classList.add("grid-cell");
cell.style.width = `${gridSize}px`;
cell.style.height = `${gridSize}px`;
cell.style.backgroundSize = `auto 20px`;
cell.style.backgroundRepeat = `no-repeat`;
cell.style.backgroundPosition = `center center`;
cell.style.backgroundImage =
"url('https://www.freeiconspng.com/thumbs/cursor-png/white-mouse-cursor-arrow-by-qubodup-11.png')";
grid3.appendChild(cell);
}
}
// Create grid cells with images for grid4 (only y-direction)
for (let i = 0; i < 100; i++) {
for (let j = 0; j < 50; j++) {
const cell = document.createElement("div");
cell.classList.add("grid-cell");
cell.style.width = `${gridSize}px`;
cell.style.height = `${gridSize}px`;
cell.style.backgroundSize = `auto 20px`;
cell.style.backgroundRepeat = `no-repeat`;
cell.style.backgroundPosition = `center center`;
cell.style.backgroundImage =
"url('https://www.freeiconspng.com/thumbs/cursor-png/white-mouse-cursor-arrow-by-qubodup-11.png')";
grid4.appendChild(cell);
}
}
// Move grid along with mouse position
document.addEventListener("mousemove", (event) => {
const mouseX = event.clientX;
const mouseY = event.clientY;
// Calculate the new grid position for grid
const gridX = Math.max(0, mouseX - resetThreshold) % gridSize;
const gridY = Math.max(0, mouseY - resetThreshold) % gridSize;
// Update the grid position for grid
grid.style.transform = `translate(${gridX - gridSize}px, ${
gridY - gridSize
}px)`;
// Calculate the new grid position for grid2 with opposite direction
const gridX2 =
(Math.max(0, mouseX - resetThreshold) % gridSize) - gridSize;
const gridY2 =
(Math.max(0, mouseY - resetThreshold) % gridSize) - gridSize;
// Update the grid position for grid2
grid2.style.transform = `translate(${-gridX2}px, ${-gridY2}px)`;
// Calculate the new grid position for grid3 (only x-direction)
const gridX3 = Math.max(0, mouseX - resetThreshold) % gridSize;
const gridY3 = 0; // No movement in the y-direction
// Update the grid position for grid3
grid3.style.transform = `translate(${
gridX3 - gridSize
}px, ${-gridY3}px)`;
// Calculate the new grid position for grid4 (only y-direction)
const gridX4 = 0; // No movement in the x-direction
const gridY4 = Math.max(0, mouseY - resetThreshold) % gridSize;
// Update the grid position for grid4
grid4.style.transform = `translate(${-gridX4}px, ${
gridY4 - gridSize
}px)`;
});
}
</script>
</body>
</html>