Ring-Size-Converter / index.html
5digit's picture
Update index.html
8519151 verified
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Конвертер размеров колец</title>
<style>
body { font-family: Arial, sans-serif; }
.container { max-width: 600px; margin: auto; padding: 20px; }
input, select { width: 100%; margin: 10px 0; padding: 10px; }
.result { margin-top: 20px; }
</style>
</head>
<body>
<div class="container">
<h1>Конвертер размеров колец</h1>
<input type="number" id="value" placeholder="Введите значение" />
<select id="unitFrom">
<option value="in_diameter">Диаметр в дюймах (in)</option>
<option value="mm_diameter">Диаметр в миллиметрах (mm)</option>
<option value="in_circumference">Длина окружности в дюймах (in)</option>
<option value="mm_circumference">Длина окружности в миллиметрах (mm)</option>
</select>
<button onclick="convert()">Перевести</button>
<div class="result" id="result"></div>
</div>
<script>
function convert() {
const value = parseFloat(document.getElementById('value').value);
const unitFrom = document.getElementById('unitFrom').value;
const resultDiv = document.getElementById('result');
if (isNaN(value)) {
resultDiv.innerHTML = "Пожалуйста, введите корректное значение.";
return;
}
// Переменные для хранения результатов
let inDiameter, mmDiameter, inCircumference, mmCircumference;
// Конвертация входного значения
if (unitFrom === 'in_diameter') {
inDiameter = value;
mmDiameter = value * 25.4; // 1 дюйм = 25.4 мм
inCircumference = value * Math.PI; // C = π * d
mmCircumference = mmDiameter * Math.PI; // C = π * d
} else if (unitFrom === 'mm_diameter') {
mmDiameter = value;
inDiameter = value / 25.4; // 1 мм = 0.03937 дюйма
inCircumference = inDiameter * Math.PI;
mmCircumference = value * Math.PI;
} else if (unitFrom === 'in_circumference') {
inCircumference = value;
mmCircumference = value * 25.4; // 1 дюйм = 25.4 мм
inDiameter = value / Math.PI; // d = C / π
mmDiameter = inDiameter * 25.4;
} else if (unitFrom === 'mm_circumference') {
mmCircumference = value;
inCircumference = value / 25.4; // 1 мм = 0.03937 дюйма
mmDiameter = value / Math.PI; // d = C / π
inDiameter = mmDiameter / 25.4;
}
// Формирование вывода
resultDiv.innerHTML = `
<strong>Результаты:</strong><br>
Диаметр:<br>
${inDiameter.toFixed(4)} дюймов (in)<br>
${mmDiameter.toFixed(4)} миллиметров (mm)<br>
<br>
Длина окружности:<br>
${inCircumference.toFixed(4)} дюймов (in)<br>
${mmCircumference.toFixed(4)} миллиметров (mm)
`;
}
</script>
</body>
</html>