Форум по Javascript
-
Anonymous
Игра с цветными коробками с низкой непрозрачностью
Сообщение
Anonymous »
Цветное поле с низкой непрозрачностью
Код: Выделить всё
Dynamic Table
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
table {
border-collapse: collapse;
}
td {
width: 50px;
height: 50px;
text-align: center;
vertical-align: middle;
border: 1px solid #ddd;
cursor: pointer;
}
Код: Выделить всё
< /code>
java script:
const tablecontainer = document.getelementbyid ('table-container'); < /p>
let size = 2; < /p>
function createable (size) {< /p>
const table = document.createElement('table');
table.id = 'dynamicTable';
const backgroundColor = getRandomColor();
for (let i = 0; i < size; i++) {
const row = document.createElement('tr');
for (let j = 0; j < size; j++) {
const cell = document.createElement('td');
cell.style.backgroundColor = backgroundColor;
cell.addEventListener('click', () => handleCellClick(cell));
row.appendChild(cell);
}
table.appendChild(row);
}
return table;
< /code>
} < /p>
function getRandomColor () {< /p>
const letters = '0123456789ABCDEF';
let color = '#';
for (let i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
< /code>
} < /p>
Функция случайной Rededuceopacity (таблица) {< /p>
const cells = table.querySelectorAll('td');
const randomIndex = Math.floor(Math.random() * cells.length);
const randomCell = cells[randomIndex];
randomCell.style.opacity = 0.5;
randomCell.classList.add('reduced-opacity');
< /code>
} < /p>
function handlecellclick (cell) {< /p>
if (cell.classList.contains('reduced-opacity') && size < 10) {
size++;
tableContainer.innerHTML = '';
const newTable = createTable(size);
tableContainer.appendChild(newTable);
randomlyReduceOpacity(newTable);
}
}
const InitialTable = createTable(size);
tableContainer.appendChild(initialTable);< /p>
randomlyReduceOpacity(initialTable);
Подробнее здесь:
https://stackoverflow.com/questions/793 ... r-box-game
1737696798
Anonymous
Цветное поле с низкой непрозрачностью
[code]
Dynamic Table
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
table {
border-collapse: collapse;
}
td {
width: 50px;
height: 50px;
text-align: center;
vertical-align: middle;
border: 1px solid #ddd;
cursor: pointer;
}
[/code]
[code]
< /code>
java script:
const tablecontainer = document.getelementbyid ('table-container'); < /p>
let size = 2; < /p>
function createable (size) {< /p>
const table = document.createElement('table');
table.id = 'dynamicTable';
const backgroundColor = getRandomColor();
for (let i = 0; i < size; i++) {
const row = document.createElement('tr');
for (let j = 0; j < size; j++) {
const cell = document.createElement('td');
cell.style.backgroundColor = backgroundColor;
cell.addEventListener('click', () => handleCellClick(cell));
row.appendChild(cell);
}
table.appendChild(row);
}
return table;
< /code>
} < /p>
function getRandomColor () {< /p>
const letters = '0123456789ABCDEF';
let color = '#';
for (let i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
< /code>
} < /p>
Функция случайной Rededuceopacity (таблица) {< /p>
const cells = table.querySelectorAll('td');
const randomIndex = Math.floor(Math.random() * cells.length);
const randomCell = cells[randomIndex];
randomCell.style.opacity = 0.5;
randomCell.classList.add('reduced-opacity');
< /code>
} < /p>
function handlecellclick (cell) {< /p>
if (cell.classList.contains('reduced-opacity') && size < 10) {
size++;
tableContainer.innerHTML = '';
const newTable = createTable(size);
tableContainer.appendChild(newTable);
randomlyReduceOpacity(newTable);
}
[/code]
}
const InitialTable = createTable(size);
tableContainer.appendChild(initialTable);< /p>
randomlyReduceOpacity(initialTable);
Подробнее здесь: [url]https://stackoverflow.com/questions/79383319/low-opacity-color-box-game[/url]