Spaces:
Running
Running
Add 1 files
Browse files- index.html +91 -6
index.html
CHANGED
|
@@ -43,6 +43,13 @@
|
|
| 43 |
background: #667eea;
|
| 44 |
cursor: pointer;
|
| 45 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
</style>
|
| 47 |
</head>
|
| 48 |
<body class="min-h-screen bg-gray-50">
|
|
@@ -103,12 +110,39 @@
|
|
| 103 |
</div>
|
| 104 |
|
| 105 |
<div class="mt-6">
|
| 106 |
-
<
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
</div>
|
| 113 |
</div>
|
| 114 |
|
|
@@ -207,6 +241,10 @@
|
|
| 207 |
document.getElementById('femaleBtn').addEventListener('click', () => setGender('female'));
|
| 208 |
document.getElementById('bodyfat').addEventListener('input', updateBodyfatValue);
|
| 209 |
document.getElementById('calculateBtn').addEventListener('click', calculateNutrition);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
|
| 211 |
// Funciones
|
| 212 |
function setGender(selectedGender) {
|
|
@@ -219,9 +257,25 @@
|
|
| 219 |
if (selectedGender === 'male') {
|
| 220 |
document.getElementById('maleBtn').classList.remove('bg-blue-100', 'text-blue-700');
|
| 221 |
document.getElementById('maleBtn').classList.add('gradient-bg', 'text-white');
|
|
|
|
| 222 |
} else {
|
| 223 |
document.getElementById('femaleBtn').classList.remove('bg-pink-100', 'text-pink-700');
|
| 224 |
document.getElementById('femaleBtn').classList.add('gradient-bg', 'text-white');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
}
|
| 226 |
}
|
| 227 |
|
|
@@ -230,6 +284,37 @@
|
|
| 230 |
document.getElementById('bodyfatValue').textContent = `${bodyfat}%`;
|
| 231 |
}
|
| 232 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
function calculateNutrition() {
|
| 234 |
// Obtener valores del formulario
|
| 235 |
const age = parseInt(document.getElementById('age').value);
|
|
|
|
| 43 |
background: #667eea;
|
| 44 |
cursor: pointer;
|
| 45 |
}
|
| 46 |
+
.tab-btn {
|
| 47 |
+
transition: all 0.3s ease;
|
| 48 |
+
}
|
| 49 |
+
.tab-btn.active {
|
| 50 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 51 |
+
color: white;
|
| 52 |
+
}
|
| 53 |
</style>
|
| 54 |
</head>
|
| 55 |
<body class="min-h-screen bg-gray-50">
|
|
|
|
| 110 |
</div>
|
| 111 |
|
| 112 |
<div class="mt-6">
|
| 113 |
+
<div class="flex mb-4">
|
| 114 |
+
<button id="manualTab" class="tab-btn px-4 py-2 rounded-l-lg border border-gray-300 font-medium active">Manual</button>
|
| 115 |
+
<button id="calculateTab" class="tab-btn px-4 py-2 rounded-r-lg border border-gray-300 font-medium">Calcular % Grasa</button>
|
| 116 |
+
</div>
|
| 117 |
+
|
| 118 |
+
<div id="manualBodyfatSection">
|
| 119 |
+
<label class="block text-gray-700 mb-2">% Grasa corporal</label>
|
| 120 |
+
<input type="range" id="bodyfat" class="w-full" min="5" max="50" value="20">
|
| 121 |
+
<div class="flex justify-between text-sm text-gray-600 mt-1">
|
| 122 |
+
<span>5%</span>
|
| 123 |
+
<span id="bodyfatValue">20%</span>
|
| 124 |
+
<span>50%</span>
|
| 125 |
+
</div>
|
| 126 |
+
</div>
|
| 127 |
+
|
| 128 |
+
<div id="calculateBodyfatSection" class="hidden">
|
| 129 |
+
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-4">
|
| 130 |
+
<div>
|
| 131 |
+
<label class="block text-gray-700 mb-2">Cuello (cm)</label>
|
| 132 |
+
<input type="number" id="neck" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" min="20" max="50" value="38">
|
| 133 |
+
</div>
|
| 134 |
+
<div>
|
| 135 |
+
<label class="block text-gray-700 mb-2">Cintura (cm)</label>
|
| 136 |
+
<input type="number" id="waist" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" min="50" max="150" value="80">
|
| 137 |
+
</div>
|
| 138 |
+
<div id="hipSection">
|
| 139 |
+
<label class="block text-gray-700 mb-2">Cadera (cm)</label>
|
| 140 |
+
<input type="number" id="hip" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" min="60" max="150" value="95">
|
| 141 |
+
</div>
|
| 142 |
+
</div>
|
| 143 |
+
<button id="calculateBodyfatBtn" class="w-full bg-gray-200 text-gray-800 py-2 rounded-lg font-medium hover:bg-gray-300 transition duration-300">
|
| 144 |
+
Calcular % Grasa
|
| 145 |
+
</button>
|
| 146 |
</div>
|
| 147 |
</div>
|
| 148 |
|
|
|
|
| 241 |
document.getElementById('femaleBtn').addEventListener('click', () => setGender('female'));
|
| 242 |
document.getElementById('bodyfat').addEventListener('input', updateBodyfatValue);
|
| 243 |
document.getElementById('calculateBtn').addEventListener('click', calculateNutrition);
|
| 244 |
+
document.getElementById('manualTab').addEventListener('click', () => switchBodyfatTab('manual'));
|
| 245 |
+
document.getElementById('calculateTab').addEventListener('click', () => switchBodyfatTab('calculate'));
|
| 246 |
+
document.getElementById('calculateBodyfatBtn').addEventListener('click', calculateBodyfatPercentage);
|
| 247 |
+
document.getElementById('gender').addEventListener('change', toggleHipInput);
|
| 248 |
|
| 249 |
// Funciones
|
| 250 |
function setGender(selectedGender) {
|
|
|
|
| 257 |
if (selectedGender === 'male') {
|
| 258 |
document.getElementById('maleBtn').classList.remove('bg-blue-100', 'text-blue-700');
|
| 259 |
document.getElementById('maleBtn').classList.add('gradient-bg', 'text-white');
|
| 260 |
+
document.getElementById('hipSection').classList.add('hidden');
|
| 261 |
} else {
|
| 262 |
document.getElementById('femaleBtn').classList.remove('bg-pink-100', 'text-pink-700');
|
| 263 |
document.getElementById('femaleBtn').classList.add('gradient-bg', 'text-white');
|
| 264 |
+
document.getElementById('hipSection').classList.remove('hidden');
|
| 265 |
+
}
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
function switchBodyfatTab(tab) {
|
| 269 |
+
if (tab === 'manual') {
|
| 270 |
+
document.getElementById('manualTab').classList.add('active');
|
| 271 |
+
document.getElementById('calculateTab').classList.remove('active');
|
| 272 |
+
document.getElementById('manualBodyfatSection').classList.remove('hidden');
|
| 273 |
+
document.getElementById('calculateBodyfatSection').classList.add('hidden');
|
| 274 |
+
} else {
|
| 275 |
+
document.getElementById('manualTab').classList.remove('active');
|
| 276 |
+
document.getElementById('calculateTab').classList.add('active');
|
| 277 |
+
document.getElementById('manualBodyfatSection').classList.add('hidden');
|
| 278 |
+
document.getElementById('calculateBodyfatSection').classList.remove('hidden');
|
| 279 |
}
|
| 280 |
}
|
| 281 |
|
|
|
|
| 284 |
document.getElementById('bodyfatValue').textContent = `${bodyfat}%`;
|
| 285 |
}
|
| 286 |
|
| 287 |
+
function calculateBodyfatPercentage() {
|
| 288 |
+
const neck = parseFloat(document.getElementById('neck').value);
|
| 289 |
+
const waist = parseFloat(document.getElementById('waist').value);
|
| 290 |
+
const height = parseFloat(document.getElementById('height').value);
|
| 291 |
+
|
| 292 |
+
// F贸rmula de la Marina de EE.UU. para calcular % de grasa corporal
|
| 293 |
+
let bodyfatPercentage;
|
| 294 |
+
|
| 295 |
+
if (gender === 'male') {
|
| 296 |
+
// F贸rmula para hombres
|
| 297 |
+
bodyfatPercentage = 86.010 * Math.log10(waist - neck) - 70.041 * Math.log10(height) + 36.76;
|
| 298 |
+
} else {
|
| 299 |
+
// F贸rmula para mujeres (necesita medida de cadera)
|
| 300 |
+
const hip = parseFloat(document.getElementById('hip').value);
|
| 301 |
+
bodyfatPercentage = 163.205 * Math.log10(waist + hip - neck) - 97.684 * Math.log10(height) - 78.387;
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
// Asegurarse que el porcentaje est茅 dentro de l铆mites razonables
|
| 305 |
+
bodyfatPercentage = Math.max(5, Math.min(50, bodyfatPercentage));
|
| 306 |
+
|
| 307 |
+
// Actualizar el slider y el valor mostrado
|
| 308 |
+
document.getElementById('bodyfat').value = Math.round(bodyfatPercentage);
|
| 309 |
+
document.getElementById('bodyfatValue').textContent = `${Math.round(bodyfatPercentage)}%`;
|
| 310 |
+
|
| 311 |
+
// Mostrar notificaci贸n de 茅xito
|
| 312 |
+
alert(`Tu porcentaje de grasa corporal calculado es: ${Math.round(bodyfatPercentage)}%`);
|
| 313 |
+
|
| 314 |
+
// Cambiar a la pesta帽a manual para mostrar el resultado
|
| 315 |
+
switchBodyfatTab('manual');
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
function calculateNutrition() {
|
| 319 |
// Obtener valores del formulario
|
| 320 |
const age = parseInt(document.getElementById('age').value);
|