Resistor's value

In this example below you will see how to do a Resistor's value with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by phcacique, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright phcacique ©
  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Resistor's value</title>
  
  
  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  <section>
        
        <section id="resistor">
            <div class="conector"></div>
            <div class="lateral">
                <div class="cor0" id="faixa1"></div>
            </div>
            <div class="meio">
                <div class="cor0" id="faixa2"></div>
                <div class="cor0" id="faixa3"></div>
            </div>
            <div class="lateral"></div>
            <div class="conector"></div>
        </section>
        
        <nav>
            <label for="f1">Faixa 1</label>
            <select id="f1" name="f1">
                <option value="0">Preto</option>
                <option value="1">Marrom</option>
                <option value="2">Vermelho</option>
                <option value="3">Laranja</option>
                <option value="4">Amarelo</option>
                <option value="5">Verde</option>
                <option value="6">Azul</option>
                <option value="7">Violeta</option>
                <option value="8">Cinza</option>
                <option value="9">Branco</option>
            </select>
            <label for="f2">Faixa 2</label>
            <select id="f2" name="f2">
                <option value="0">Preto</option>
                <option value="1">Marrom</option>
                <option value="2">Vermelho</option>
                <option value="3">Laranja</option>
                <option value="4">Amarelo</option>
                <option value="5">Verde</option>
                <option value="6">Azul</option>
                <option value="7">Violeta</option>
                <option value="8">Cinza</option>
                <option value="9">Branco</option>
            </select>
            <label for="f3">Faixa 3</label>
            <select id="f3" name="f3">
                <option value="0">Preto</option>
                <option value="1">Marrom</option>
                <option value="2">Vermelho</option>
                <option value="3">Laranja</option>
                <option value="4">Amarelo</option>
                <option value="5">Verde</option>
                <option value="6">Azul</option>
                <option value="7">Violeta</option>
                <option value="8">Cinza</option>
                <option value="9">Branco</option>
            </select>
        </nav>
        <section id="valor"></section>
    </section>
  
  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/phcacique/resistorandaposs-value-yPwgpV */
*{
    font-family: monospace;
}

html, body{
    height: 100%;
    margin:0;
}

body, .lateral, .meio, #resistor{
    display: flex;
    justify-content: center;
    align-items: center;
}

#valor{
    background-color: #000;
    height: 20px;
    margin-top: 10px;
    padding: 5px;
    color: #fff;
}

#resistor{
    margin: 20px;
}

.lateral{
    width: 40px;
    height: 40px;
    background-color: #f3d8b6;
    border-radius: 10px;
}

.meio{
    width: 40px;
    height: 30px;
    background-color: #f3d8b6;
    margin: -1px;
}

.cor0, .cor1, .cor2, .cor3, .cor4, .cor5, .cor6, .cor7, .cor8, .cor9{
    height: 100%;
    width: 10px;
    margin: 0 5px;
}

.cor0{
    background-color: #000000;
}

.cor1{
    background-color: #734f4f;
}

.cor2{
    background-color: #d51a1a;
}

.cor3{
    background-color: #f38c0b;
}

.cor4{
    background-color: #f6e91d;
}

.cor5{
    background-color: #5bb51e;
}

.cor6{
    background-color: #1177f9;
}

.cor7{
    background-color: #8111f9;
}

.cor8{
    background-color: #acacac;
}

.cor9{
    background-color: #ffffff;
}

.conector{
    background-color: #acacac;
    height: 5px;
    width:30px;
}

/*Downloaded from https://www.codeseek.co/phcacique/resistorandaposs-value-yPwgpV */
var faixa1, faixa2, faixa3;
var f1, f2, f3;
var valor;
var num1 = 0, num2 = 0, num3 = 0;

window.onload = function(){
    //inicializa as variáveis
    faixa1 = document.getElementById("faixa1");
    faixa2 = document.getElementById("faixa2");
    faixa3 = document.getElementById("faixa3");
    f1 = document.getElementById("f1");
    f2 = document.getElementById("f2");
    f3 = document.getElementById("f3");
    valor = document.getElementById("valor");
    
    //adiciona os eventos
    f1.onchange = seleciona;
    f2.onchange = seleciona;
    f3.onchange = seleciona;
    
    mostraValor();
}

function seleciona(){
    if(event.target == f1) num1 = event.target.value;
    else if(event.target == f2) num2 = event.target.value;
    else if(event.target == f3) num3 = parseInt(event.target.value);
    mostraValor();
}

function mostraValor(){
    var v = num1+num2;
    for(var i=0; i<num3; i++){
        v+="0";
    }
    v+="Ω";
    valor.innerHTML = v;
    faixa1.className = "cor"+num1;
    faixa2.className = "cor"+num2;
    faixa3.className = "cor"+num3;
}

Comments