Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="modal">Please, choose a light mode.</div>
<div id="main">
    <div id="button-panel">
        <div id="sign">Light Modes</div>
        <div class="buttons">
            <button id="normal">Normal</button>
            <button id="outage">Outage</button>
            <button id="on">On</button>
            <button id="off">Off</button>

        </div>
    </div>
    <div id="base">
        <div class="circle red" id="red"></div>
        <div class="circle yellow" id="yellow"></div>
        <div class="circle green" id="green"></div>
    </div>
    <!--     <div id="base">
        <div class="circle" id="red"></div>
        <div class="circle" id="yellow"></div>
        <div class="circle" id="green"></div>
    </div> -->
</div>
              
            
!

CSS

              
                * {
    margin: 0;
    padding: 0;
    user-select: none;
}
:root {
    --black: rgb(30, 30, 30);
    --red: rgb(250, 25, 25);
    --red-shadow: rgb(100, 0, 0);
    --yellow: rgb(250, 200, 0);
    --yellow-shadow: rgb(100, 0, 0);
    --green: rgb(50, 200, 50);
    --green-shadow: rgb(0, 50, 0);
    --dark-gray: rgb(120, 120, 120);
    --med-gray: rgb(170, 170, 170);
    --light-gray: rgb(200, 200, 200);
    --graydient: linear-gradient(
        to bottom right,
        var(--light-gray),
        var(--med-gray)
    );
}
body {
    background: var(--med-gray);
    /*     display: flex;
    justify-content: center; */
}
#modal {
    background-color: var(--light-gray);
    opacity: 0.8;
    border: 1px dashed var(--black);
    color: var(--black);
    width: 250px;
    text-align: center;

    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 3;
}
#main {
    display: flex;
    align-items: center;
    justify-content: space-around;
    width: 350px;

    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}
#button-panel {
    border: 3px double black;
    background-image: var(--graydient);
    box-shadow: -2px -2px 10px var(--light-gray), 2px 2px 10px var(--dark-gray);
    padding: 5px;
    width: 100px;
    height: 150px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    justify-content: space-evenly;
    z-index: 1;
}
#sign {
    color: var(--black);
}
.buttons {
    display: flex;
    flex-direction: column;
    gap: 5px;
}
button {
    width: 70px;
    transform: scale(1.025);
    text-transform: uppercase;
    box-shadow: 0px 0px 5px var(--dark-gray);
}
/* button:hover {
    background: var(--yellow);
} */
#base {
    background: var(--black);
    height: 200px;
    width: 80px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    justify-content: center;
    align-items: center;
    border-radius: 5px;
    border: 5px solid orange;
    box-shadow: 5px 2px 25px var(--black);

    /*     position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%); */
}
.circle {
    //border: 1px solid var(--black);
    height: 45px;
    width: 45px;
    border-radius: 50%;
    opacity: 0.25;
}
.circle:hover {
    transform: scale(1.1);
}

#red {
    background-image: linear-gradient(
        to bottom right,
        var(--red) 50%,
        var(--red-shadow)
    );
    box-shadow: -2px -2px 10px var(--red);
}
#yellow {
    background-image: linear-gradient(
        to bottom right,
        var(--yellow) 50%,
        var(--yellow-shadow)
    );
    box-shadow: -2px -2px 10px var(--yellow);
}
#green {
    background-image: linear-gradient(
        to bottom right,
        var(--green) 50%,
        var(--green-shadow)
    );
    box-shadow: -2px -2px 10px var(--green);
}

.outage {
    animation: blink 0.5s infinite alternate;
}
@keyframes blink {
    0% {
        opacity: 1;
    }
    100% {
        opacity: 0.25;
    }
}
/* button:active {
    transform: scale(1.5)
} */

              
            
!

JS

              
                const redLight = document.querySelector(".red");
const yellowLight = document.querySelector("#yellow");
const greenLight = document.querySelector("#green");
const INTERVAL = 1000;

const normalButton = document.querySelector("#normal");
normalButton.addEventListener("click", activateNormalMode);

const outageButton = document.querySelector("#outage");
outageButton.addEventListener("click", activateOutageMode);

const onButton = document.querySelector("#on");
onButton.addEventListener("click", () => {
    resetButtons();
    highlightButton(onButton);
    lights.forEach((light) => {
        light.classList.remove("outage");
        light.style.opacity = 1;
    });
    normalButton.addEventListener("click", activateNormalMode);
});

const offButton = document.querySelector("#off");
offButton.addEventListener("click", () => {
    resetButtons();
    highlightButton(offButton);
    //offButton.style.visibility = "hidden";
    lights.forEach((light) => {
        light.classList.remove("outage");
        lights.forEach((light) => {
            light.style.opacity = 0.25;
        });
    });
    normalButton.addEventListener("click", activateNormalMode);
});
// TODO:  Create function to turn the lights off, so I can possibly use it elsewhere in the code.

const buttons = Array.from(document.querySelectorAll("button"));

const lights = [greenLight, yellowLight, redLight];

function activateNormalMode() {
    console.log("activated normal mode");
    resetButtons();
    highlightButton(normalButton);
    lights.forEach((light) => {
        light.classList.remove("outage");
    });
    const tick = setInterval(changeLight, INTERVAL);
    // Temporarily remove listener to avoid weird timing
    normalButton.removeEventListener("click", activateNormalMode);
    [onButton, offButton, outageButton].forEach((button) => {
        button.addEventListener("click", () => {
            clearInterval(tick);
        });
    });
    normalButton.addEventListener("click", () => {
        // clearInterval(tick);
        lights.forEach((light) => (light.style.opacity = 0.25));
        // normalButton.addEventListener("click", activateNormalMode);
    });
}

let i = 0;
function changeLight() {
    lights.forEach((light) => (light.style.opacity = 0.25));
    lights[i % lights.length].style.opacity = 1;
    i++;
}

function activateOutageMode() {
    console.log("activated outage mode");
    resetButtons();
    highlightButton(outageButton);
    lights.forEach((light) => {
        light.style.opacity = 0.25;
    });
    red.classList.add("outage");
    normalButton.addEventListener("click", activateNormalMode);
}

function resetButtons() {
    buttons.forEach((button) => {
        button.style = "initial";
    });
}

// Simulates pushing the button in
function highlightButton(button) {
    button.style.scale = ".975";
    button.style.boxShadow =
        "1px 1px 2px var(--med-gray) inset, 1px 1px 2px var(--light-gray)";
}

const modal = document.querySelector("#modal");
document.addEventListener("click", (e) => {
    e.preventDefault();
    console.log(e.target.value);
    modal.style.visibility = "hidden";
});

activateNormalMode();

setTimeout(() => {
    modal.style.visibility = "hidden";
}, 3000);

              
            
!
999px

Console