<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Calculadora de Ganhos do plano</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="calculator">
<h1>Calculadora de benefícios EcoMilhas</h1>
<div class="slider-container">
<label for="andar">Caminhar (km): <span id="andarValue">0</span></label>
<input type="range" id="andar" min="0" max="100" step="1" value="0" oninput="updateValue('andar')">
</div>
<div class="slider-container">
<label for="bicicleta">Bicicleta (km): <span id="bicicletaValue">0</span></label>
<input type="range" id="bicicleta" min="0" max="100" step="1" value="0" oninput="updateValue('bicicleta')">
</div>
<div class="slider-container">
<label for="onibus">Ônibus (km): <span id="onibusValue">0</span></label>
<input type="range" id="onibus" min="0" max="100" step="1" value="0" oninput="updateValue('onibus')">
</div>
<div class="slider-container">
<label for="metro">Metrô (km): <span id="metroValue">0</span></label>
<input type="range" id="metro" min="0" max="100" step="1" value="0" oninput="updateValue('metro')">
</div>
<div class="slider-container">
<label for="carroEletrico">Carro Elétrico (km): <span id="carroEletricoValue">0</span></label>
<input type="range" id="carroEletrico" min="0" max="100" step="1" value="0" oninput="updateValue('carroEletrico')">
</div>
<div class="slider-container">
<label for="carroEtanol">Carro a Etanol (km): <span id="carroEtanolValue">0</span></label>
<input type="range" id="carroEtanol" min="0" max="100" step="1" value="0" oninput="updateValue('carroEtanol')">
</div>
<button onclick="calculateEcoMilhas()">Calcular</button>
<p id="result"></p>
<p id="benefits"></p>
</div>
<script src="script.js"></script>
</body>
</html>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f0f0f0;
margin: 0;
}
.calculator {
background-color: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
text-align: center;
width: 300px;
}
.slider-container {
margin: 10px 0;
}
input[type="range"] {
-webkit-appearance: none;
width: 100%;
height: 8px;
background: linear-gradient(to right, #740D6A 0%, #740D6A 0%, #d3d3d3 0%, #d3d3d3 100%);
outline: none;
opacity: 0.7;
transition: opacity 0.2s;
cursor: pointer;
}
input[type="range"]:hover {
opacity: 1;
}
input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
background: #740D6A;
cursor: pointer;
border-radius: 50%;
}
input[type="range"]::-moz-range-thumb {
width: 25px;
height: 25px;
background: #740D6A;
cursor: pointer;
border-radius: 50%;
}
button {
padding: 10px;
margin: 10px 0;
width: 100%;
box-sizing: border-box;
border: 1px solid #ccc;
border-radius: 5px;
background-color: #28a745;
color: white;
cursor: pointer;
}
button:hover {
background-color: #218838;
}
#result, #benefits {
font-size: 1.2em;
margin-top: 10px;
}
const modalRates = {
"andar": 0.25,
"bicicleta": 0.25,
"onibus": 0.176,
"metro": 0.244,
"carroEletrico": 0.125,
"carroEtanol": 0.0975
};
const ecoMilhaValue = 0.70; // Valor em reais por EcoMilha
function updateValue(modal) {
const slider = document.getElementById(modal);
const valueDisplay = document.getElementById(`${modal}Value`);
valueDisplay.textContent = slider.value;
updateSliderBackground(slider);
}
function updateSliderBackground(slider) {
const value = (slider.value - slider.min) / (slider.max - slider.min) * 100;
slider.style.background = `linear-gradient(to right, #740D6A ${value}%, #d3d3d3 ${value}%)`;
}
function calculateEcoMilhas() {
let totalEcoMilhas = 0;
for (let modal in modalRates) {
const distance = parseFloat(document.getElementById(modal).value);
totalEcoMilhas += distance * modalRates[modal];
}
const totalBenefits = totalEcoMilhas * ecoMilhaValue;
document.getElementById('result').textContent = `Você vai ganhar ${totalEcoMilhas.toFixed(2)} EcoMilhas!`;
document.getElementById('benefits').textContent = `Isso equivale a R$${totalBenefits.toFixed(2)} em benefícios no nosso app.`;
}
// Inicialize os sliders com a cor de fundo correta
document.querySelectorAll('input[type="range"]').forEach(slider => {
updateSliderBackground(slider);
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.