Перейти к содержимому
×
Главная
Бизнес-информатика
Web-программирование
Новости
Статьи
☰ Меню
Color:
Blue
Red
Green
Yellow
Black
Shape:
Circle
Square
Pill
Rectangle
Background:
Border:
const colorButtons = document.getElementsByClassName("color-button"); const shapeButtons = document.getElementsByClassName("shape-button"); const backgroundCheckbox = document.getElementById("background-checkbox"); const borderCheckbox = document.getElementById("border-checkbox"); const preview = document.getElementById("preview"); let currentColor = "blue"; for (let i = 0; i < colorButtons.length; i++) { colorButtons[i].addEventListener("click", function() { currentColor = this.innerHTML.toLowerCase(); preview.style.backgroundColor = currentColor; }); } for (let i = 0; i < shapeButtons.length; i++) { shapeButtons[i].addEventListener("click", function() { preview.className = "shape " + this.innerHTML.toLowerCase(); }); } backgroundCheckbox.addEventListener("change", function() { if (this.checked) { preview.style.visibility = "hidden"; preview.style.border = "1px solid black"; } else { preview.style.visibility = "visible"; preview.style.border = "none"; } }); borderCheckbox.addEventListener("change", function() { if (this.checked) { preview.style.border = "1px solid black"; preview.style.outline = "2px solid red"; } else { preview.style.visibility = "visible"; preview.style.border = "none"; preview.style.outline = "none"; } });
.shape { width: 100px; height: 100px; margin: 10px; } .circle { border-radius: 50% } .square { border-radius: 0; } .pill { border-radius: 50px; width: 150px; } .rectangle { border-radius: 0; width: 150px; }
Results:
Color:
Blue
Red
Green
Yellow
Black
Shape:
Circle
Square
Pill
Rectangle
Background:
Border: