Главная
Направление
Новости
Мои работы
Мои статьи
Select a color
Blue
Red
Green
Yellow
Black
Select a shape
Circle
Square
Pill
Rectangle
Customize
Border
Background
$(function () { function handleShape(e) { $(".shape").removeClass("circle pill square rectangle").addClass($(e.target).val()) }; function handleToggle(e) { var target = $(e.target); if (target.is(".brand-toggle")) { var checked = target.is(":checked"), value = $("[name='brand']").filter(":checked").attr("data-" + target[0].id); $(".shape").css(target[0].id, checked ? value : "") } else { $(".shape").toggleClass(target[0].id, target.is(":checked")) } } function updateBrand() { handleShape({ target: $("[name='shape']:checked") }); $(".toggle:checked").each(function () { handleToggle({ target: $(this) }) }) } $(".controls input").checkboxradio(); $(".shape-bar, .brand").controlgroup(); $(".toggles").controlgroup({ direction: "vertical" }); $("[name='shape']").on("change", handleShape); $(".toggle").on("change", handleToggle); $("[name='brand']").on("change", updateBrand); updateBrand() });
.shape { margin-left: 4em; margin-top: 2.5em; height: 8em; width: 8em; box-shadow: 4px 4px 8px; color: #ccc; background-repeat: no-repeat; background-size: 90%; background-position: 50%; } .circle, .pill { border-radius: 8em; } .pill, .rectangle { width: 16em; } .square, .circle { margin-left: 9em; } .border { border: 2px solid #333333; } .toggles { width: 200px; } .toggle-wrap, .shape { display: inline-block; vertical-align: top; } .controls { background: #ccc; padding: 1em; display: inline-block; } .editors-buttons { display: none; }
Results:
Select a color
Blue
Red
Green
Yellow
Black
Select a shape
Circle
Square
Pill
Rectangle
Customize
Border
Background