-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
imgtiles.html
103 lines (94 loc) · 3.14 KB
/
imgtiles.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tile Reveal Game</title>
<style>
#image-container {
position: relative;
width: 800px;
height: 600px;
background: black;
display: grid;
grid-template-columns: repeat(8, 1fr); /* 8 columns */
grid-template-rows: repeat(6, 1fr); /* 6 rows */
gap: 1px;
}
.tile {
position: relative;
width: 100%;
height: 100%;
background: grey;
display: flex;
align-items: center;
justify-content: center;
font-size: 20px;
color: white;
cursor: pointer;
overflow: hidden;
}
.revealed {
background-color: transparent;
background-size: 800px 600px;
}
#controls {
margin-bottom: 20px;
}
</style>
</head>
<body>
<h1>Tile Reveal Game</h1>
<div id="controls">
<label for="image-url">Enter Image URL:</label>
<input type="text" id="image-url" placeholder="Enter image URL" />
<button onclick="loadImage()">Load Image</button>
</div>
<div id="image-container"></div>
<script>
const imageContainer = document.getElementById('image-container');
const controls = document.getElementById('controls');
const tileSize = { width: 100, height: 100 }; // 100x100px tiles for 800x600 grid
function loadImage() {
const imageUrl = document.getElementById('image-url').value;
imageContainer.innerHTML = ''; // Clear any previous tiles
for (let row = 0; row < 6; row++) { // 6 rows
for (let col = 0; col < 8; col++) { // 8 columns
const tile = document.createElement('div');
tile.classList.add('tile');
tile.dataset.row = row;
tile.dataset.col = col;
// Add the number to each tile
tile.innerText = row * 8 + col + 1;
// Reveal image on click
tile.addEventListener('click', () => {
tile.style.backgroundImage = `url(${imageUrl})`;
tile.style.backgroundPosition = `-${col * tileSize.width}px -${row * tileSize.height}px`;
tile.classList.add('revealed'); // Apply the revealed class for styling
tile.innerText = ''; // Hide number once clicked
});
imageContainer.appendChild(tile);
}
}
updateURL();
controls.style.display = 'none'; // Hide controls after image is loaded
}
function updateURL() {
const imageUrl = document.getElementById('image-url').value;
const newUrl = `${window.location.origin}${window.location.pathname}?image=${encodeURIComponent(imageUrl)}`;
history.pushState(null, '', newUrl);
}
// Load image from URL on page load if present
window.onload = function() {
const params = new URLSearchParams(window.location.search);
const imageUrl = params.get('image');
if (imageUrl) {
document.getElementById('image-url').value = imageUrl;
loadImage();
}
};
</script>
<script async defer src="https://scripts.simpleanalyticscdn.com/latest.js"></script>
<noscript><img src="https://queue.simpleanalyticscdn.com/noscript.gif" alt="" referrerpolicy="no-referrer-when-downgrade" /></noscript>
</body>
</html>