Потужнометр з анімаціями та звуками
Нижче наведений повнофункціональний потужнометр із сучасним інтерфейсом, анімаціями та звуковими ефектами:
<!DOCTYPE html>
<html lang="uk">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Потужнометр | Power Meter</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
body {
background: linear-gradient(135deg, #1a2a6c, #b21f1f, #1a2a6c);
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
overflow: hidden;
}
.container {
width: 100%;
max-width: 800px;
background: rgba(0, 0, 0, 0.7);
backdrop-filter: blur(10px);
border-radius: 20px;
box-shadow: 0 15px 30px rgba(0, 0, 0, 0.5);
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.1);
}
header {
background: linear-gradient(to right, #0f0c29, #302b63, #24243e);
color: white;
text-align: center;
padding: 25px;
position: relative;
}
h1 {
font-size: 2.8rem;
letter-spacing: 2px;
text-shadow: 0 0 15px rgba(0, 255, 255, 0.7);
margin-bottom: 10px;
}
.subtitle {
font-size: 1.2rem;
opacity: 0.8;
}
.meter-container {
padding: 40px;
display: flex;
flex-direction: column;
align-items: center;
}
.meter-display {
position: relative;
width: 300px;
height: 300px;
margin-bottom: 40px;
}
.meter-circle {
width: 100%;
height: 100%;
border-radius: 50%;
background: #111;
position: relative;
overflow: hidden;
box-shadow: inset 0 0 50px rgba(0, 0, 0, 0.8),
0 0 0 10px #0a0a2a,
0 0 30px rgba(0, 100, 255, 0.6);
}
.meter-fill {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 0%;
background: linear-gradient(to top, #00c9ff, #92fe9d);
border-radius: 50% 50% 0 0 / 100% 100% 0 0;
transform-origin: center bottom;
transition: height 0.5s ease-out;
box-shadow: inset 0 -10px 20px rgba(0, 0, 0, 0.3);
}
.meter-inner {
position: absolute;
top: 15px;
left: 15px;
right: 15px;
bottom: 15px;
background: #0a0a2a;
border-radius: 50%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
color: white;
z-index: 10;
box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.8);
}
.power-value {
font-size: 5rem;
font-weight: bold;
background: linear-gradient(to bottom, #ffffff, #00c9ff);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
text-shadow: 0 0 20px rgba(0, 200, 255, 0.5);
}
.power-unit {
font-size: 1.5rem;
margin-top: -15px;
color: #00c9ff;
}
.meter-markings {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.marking {
position: absolute;
top: 0;
left: 50%;
width: 4px;
height: 20px;
background: rgba(255, 255, 255, 0.3);
transform-origin: bottom center;
transform: translateX(-50%);
}
.controls {
width: 100%;
max-width: 500px;
}
.slider-container {
width: 100%;
margin-bottom: 30px;
}
.slider-label {
display: flex;
justify-content: space-between;
margin-bottom: 10px;
color: white;
font-size: 1.2rem;
}
.power-slider {
-webkit-appearance: none;
width: 100%;
height: 25px;
background: linear-gradient(to right, #00c9ff, #92fe9d);
border-radius: 12px;
outline: none;
box-shadow: 0 0 10px rgba(0, 200, 255, 0.5);
}
.power-slider::-webkit-slider-thumb {
-webkit-appearance: none;
width: 40px;
height: 40px;
border-radius: 50%;
background: white;
cursor: pointer;
box-shadow: 0 0 15px rgba(0, 0, 0, 0.8);
border: 3px solid #0a0a2a;
transition: transform 0.2s;
}
.power-slider::-webkit-slider-thumb:hover {
transform: scale(1.1);
}
.buttons {
display: flex;
justify-content: center;
gap: 20px;
margin-top: 30px;
}
.power-btn {
padding: 15px 35px;
font-size: 1.2rem;
border: none;
border-radius: 50px;
background: linear-gradient(to right, #00c9ff, #92fe9d);
color: #0a0a2a;
font-weight: bold;
cursor: pointer;
transition: all 0.3s;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}
.power-btn:hover {
transform: translateY(-3px);
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}
.power-btn:active {
transform: translateY(1px);
}
.max-power-btn {
background: linear-gradient(to right, #ff416c, #ff4b2b);
color: white;
}
.sound-control {
position: absolute;
top: 20px;
right: 20px;
background: rgba(255, 255, 255, 0.1);
border-radius: 50%;
width: 40px;
height: 40px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
backdrop-filter: blur(5px);
border: 1px solid rgba(255, 255, 255, 0.2);
}
.sound-icon {
color: white;
font-size: 1.2rem;
}
.pulse {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: 50%;
background: rgba(0, 200, 255, 0.2);
opacity: 0;
z-index: -1;
}
.power-animation {
animation: pulse 1.5s infinite;
}
@keyframes pulse {
0% {
transform: scale(0.8);
opacity: 0.7;
}
70% {
transform: scale(1.1);
opacity: 0;
}
100% {
opacity: 0;
}
}
.meter-overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: radial-gradient(circle, transparent 60%, rgba(0, 0, 0, 0.7) 100%);
border-radius: 50%;
z-index: 5;
}
.effects {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
overflow: hidden;
z-index: -1;
}
.particle {
position: absolute;
border-radius: 50%;
background: rgba(0, 200, 255, 0.5);
animation: float linear infinite;
}
@keyframes float {
to {
transform: translateY(-1000px) rotate(360deg);
}
}
footer {
padding: 20px;
text-align: center;
color: rgba(255, 255, 255, 0.6);
font-size: 0.9rem;
background: rgba(0, 0, 0, 0.3);
}
@media (max-width: 600px) {
.meter-display {
width: 250px;
height: 250px;
}
.power-value {
font-size: 4rem;
}
.power-btn {
padding: 12px 25px;
font-size: 1rem;
}
h1 {
font-size: 2.2rem;
}
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>ПОТУЖНОМЕТР</h1>
<div class="subtitle">Вимірювання та візуалізація енергії</div>
<div class="sound-control" id="soundControl">
<div class="sound-icon">🔊</div>
</div>
</header>
<div class="meter-container">
<div class="effects" id="effects"></div>
<div class="meter-display">
<div class="meter-circle">
<div class="meter-fill" id="meterFill"></div>
<div class="meter-overlay"></div>
<div class="meter-inner">
<div class="power-value" id="powerValue">0</div>
<div class="power-unit">MW</div>
</div>
<div class="pulse" id="pulse"></div>
</div>
</div>
<div class="controls">
<div class="slider-container">
<div class="slider-label">
<span>0%</span>
<span>Рівень потужності</span>
<span>100%</span>
</div>
<input type="range" min="0" max="100" value="0" class="power-slider" id="powerSlider">
</div>
<div class="buttons">
<button class="power-btn" id="increaseBtn">+10%</button>
<button class="power-btn max-power-btn" id="maxPowerBtn">МАКСИМУМ</button>
<button class="power-btn" id="decreaseBtn">-10%</button>
</div>
</div>
</div>
<footer>
© 2023 Потужнометр | Power Meter | Всі права захищені
</footer>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Елементи DOM
const powerSlider = document.getElementById('powerSlider');
const meterFill = document.getElementById('meterFill');
const powerValue = document.getElementById('powerValue');
const increaseBtn = document.getElementById('increaseBtn');
const decreaseBtn = document.getElementById('decreaseBtn');
const maxPowerBtn = document.getElementById('maxPowerBtn');
const pulse = document.getElementById('pulse');
const soundControl = document.getElementById('soundControl');
const effectsContainer = document.getElementById('effects');
// Стан звука
let soundEnabled = true;
let audioContext;
// Ініціалізація Web Audio API
function initAudio() {
if (!audioContext) {
audioContext = new (window.AudioContext || window.webkitAudioContext)();
}
}
// Функція для відтворення звуку
function playSound(frequency, duration = 0.2) {
if (!soundEnabled) return;
initAudio();
const oscillator = audioContext.createOscillator();
const gainNode = audioContext.createGain();
oscillator.type = 'sine';
oscillator.frequency.setValueAtTime(frequency, audioContext.currentTime);
gainNode.gain.setValueAtTime(0.2, audioContext.currentTime);
gainNode.gain.exponentialRampToValueAtTime(0.01, audioContext.currentTime + duration);
oscillator.connect(gainNode);
gainNode.connect(audioContext.destination);
oscillator.start();
oscillator.stop(audioContext.currentTime + duration);
}
// Функція для створення частинок
function createParticles() {
const count = Math.floor(Math.random() * 5) + 3;
for (let i = 0; i < count; i++) {
const particle = document.createElement('div');
particle.classList.add('particle');
const size = Math.random() * 10 + 2;
const left = Math.random() * 100;
const animationDuration = Math.random() * 5 + 3;
particle.style.width = `${size}px`;
particle.style.height = `${size}px`;
particle.style.left = `${left}%`;
particle.style.bottom = `-${size}px`;
particle.style.opacity = Math.random() * 0.5 + 0.3;
particle.style.animationDuration = `${animationDuration}s`;
effectsContainer.appendChild(particle);
// Видалення частинок після завершення анімації
setTimeout(() => {
particle.remove();
}, animationDuration * 1000);
}
}
// Оновлення потужнометру
function updateMeter(value) {
// Оновлення візуального відображення
meterFill.style.height = `${value}%`;
powerValue.textContent = Math.floor(value);
// Анімація пульсації при високій потужності
if (value > 70) {
pulse.classList.add('power-animation');
} else {
pulse.classList.remove('power-animation');
}
// Звукові ефекти
if (soundEnabled) {
const frequency = 100 + (value * 4);
playSound(frequency, 0.1);
}
// Створення частинок при високій потужності
if (value > 60 && Math.random() > 0.7) {
createParticles();
}
}
// Обробка зміни повзунка
powerSlider.addEventListener('input', function() {
const value = parseInt(this.value);
updateMeter(value);
});
// Кнопка збільшення
increaseBtn.addEventListener('click', function() {
let newValue = parseInt(powerSlider.value) + 10;
if (newValue > 100) newValue = 100;
powerSlider.value = newValue;
updateMeter(newValue);
playSound(300, 0.3);
});
// Кнопка зменшення
decreaseBtn.addEventListener('click', function() {
let newValue = parseInt(powerSlider.value) - 10;
if (newValue < 0) newValue = 0;
powerSlider.value = newValue;
updateMeter(newValue);
playSound(150, 0.3);
});
// Кнопка максимуму
maxPowerBtn.addEventListener('click', function() {
powerSlider.value = 100;
updateMeter(100);
playSound(600, 0.5);
// Спеціальний ефект при максимальній потужності
for (let i = 0; i < 20; i++) {
setTimeout(() => {
createParticles();
}, i * 100);
}
});
// Управління звуком
soundControl.addEventListener('click', function() {
soundEnabled = !soundEnabled;
this.querySelector('.sound-icon').textContent = soundEnabled ? '🔊' : '🔇';
if (soundEnabled) {
playSound(200, 0.1);
}
});
// Ініціалізація
updateMeter(0);
// Створення міток на потужнометрі
const meterCircle = document.querySelector('.meter-circle');
for (let i = 0; i < 36; i++) {
const marking = document.createElement('div');
marking.classList.add('marking');
marking.style.transform = `translateX(-50%) rotate(${i * 10}deg)`;
meterCircle.appendChild(marking);
}
});
</script>
</body>
</html>
Особливості потужнометра:
-
Сучасний дизайн:
- Градієнтний фон з темними тонами
- Неонова підсвітка та тіні
- Стильний круглий індикатор з підсвіткою
-
Інтерактивні елементи:
- Повзунок для регулювання потужності
- Кнопки "+10%", "-10%" та "МАКСИМУМ"
- Кнопка управління звуком
-
Анімації та візуальні ефекти:
- Плавна зміна рівня потужності
- Пульсація при високій потужності
- Партикули (частинки енергії), що з'являються при високих значеннях
- Градієнтне заповнення індикатора
-
Звукові ефекти:
- Тон, що змінює висоту в залежності від рівня потужності
- Різні звуки для кнопок
- Можливість вимкнути звук
- Спеціальний звуковий ефект при досягненні максимуму
-
Адаптивність:
- Працює на різних пристроях та розмірах екранів
- Оптимізований інтерфейс для мобільних пристроїв
Просто скопіюйте цей код у файл HTML та відкрийте у браузері, щоб використовувати потужнометр!