Git Product home page Git Product logo

color-schema-switcher-project's Introduction

Color Schema Switcher Project

This simple JavaScript project allows users to switch between predefined color schemes and generate a random background color. Below are the three main files for this project:

Screenshots

App Screenshot

HTML Code

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Color Schema Switcher</title>
    <link rel="stylesheet" href="style.css" />
    <script src="./script.js" defer></script>
  </head>

  <body>
    <section class="container">
      <h1>COLOR SCHEMA SWITCHER</h1>
      <div class="buttons-container">
        <span class="buttons" id="red">Red</span>
        <span class="buttons" id="blue">Blue</span>
        <span class="buttons" id="grey">Grey</span>
        <span class="buttons" id="yellow">Yellow</span>
      </div>
      <div class="random-background-btn">Random<br />Background</div>
    </section>
  </body>
</html>

CSS Code

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

.container {
  min-width: 80%;
  border: 1px solid #1d3557;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 10px;
  border-radius: 4px;
  box-shadow: #00000059 0px 5px 15px;
  padding: 5px;
  background-color: #ffffff;
}

.container h1 {
  color: #1d3557;
  width: 100%;
  text-align: center;
}
.buttons-container {
  padding: 10px;
  box-shadow: #00000059 0px 5px 15px;
}
.buttons-container > span {
  display: inline-block;
  width: 100px;
  padding: 5px;
  margin: 10px;
  text-align: center;
  box-shadow: #00000059 0px 5px 15px;
  cursor: pointer;
}
#red {
  background-color: red;
}
#blue {
  background-color: blue;
}
#grey {
  background-color: grey;
}
#yellow {
  background-color: yellow;
}

.random-background-btn {
  background: #ffffff;
  border: 1px solid greenyellow;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  font-weight: 800;
  background-color: #1d3557;
  color: #ffb703;
  cursor: pointer;
}

JavaScript Code

const buttons = document.querySelectorAll(".buttons");
const body = document.body;

buttons.forEach((button) => {
  button.addEventListener("click", (e) => {
    let color = e.target.id;
    switch (color) {
      case "red":
        body.style.backgroundColor = color;
        break;
      case "blue":
        body.style.backgroundColor = color;
        break;
      case "grey":
        body.style.backgroundColor = color;
        break;
      case "yellow":
        body.style.backgroundColor = color;
        break;
    }
  });
});

// Random Background Switcher
const randomBTN = document.querySelector(".random-background-btn");

// Create function to generate the random color and return rgb
const randomColor = () => {
  const min = 0;
  const max = 255;
  const red = Math.floor(Math.random() * (max - min + 1)) + min;
  const green = Math.floor(Math.random() * (max - min + 1)) + min;
  const blue = Math.floor(Math.random() * (max - min + 1)) + min;
  const rgb = `rgb(${red}, ${green}, ${blue})`;
  return rgb;
};

randomBTN.addEventListener("click", () => {
  const bg_color = randomColor();
  body.style.backgroundColor = bg_color;
});

color-schema-switcher-project's People

Contributors

bcapathshala avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.