<header>
<h2 class="title">AnimationEvent: animationName</h2>
<p class="description">Повертає назву анімації, що викликала подію</p>
</header>
<main>
<div class="result">
<button id="startBounce" class="btn">Запустити Bounce анімацію</button>
<button id="startFade" class="btn">Запустити Fade анімацію</button>
<div id="animatedBox" class="box">Тут анімація</div>
<p id="output">Анімація не запущена</p>
</div>
</main>
body {
font-size: 16px;
line-height: 1.5;
font-family: monospace;
}
header {
background-color: #f1f1f1;
margin-bottom: 25px;
padding: 15px;
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
}
header h2.title {
padding-bottom: 15px;
border-bottom: 1px solid #999;
}
header p.description {
font-style: italic;
color: #222;
}
.result {
background-color: #f8f8f8;
padding: 15px;
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
}
.box {
width: 150px;
height: 150px;
background-color: #3498db;
margin: 20px 0;
}
@keyframes bounce {
0% { transform: translateY(0); }
50% { transform: translateY(-50px); }
100% { transform: translateY(0); }
}
@keyframes fade {
0% { opacity: 1; }
100% { opacity: 0; }
}
.bounce {
animation: bounce 1s forwards;
}
.fade {
animation: fade 2s forwards;
}
.btn {
margin-right: 10px;
padding: 10px;
background-color: #333;
color: #fff;
border: none;
cursor: pointer;
}
.btn:hover {
background-color: #555;
}
const animatedBox = document.getElementById('animatedBox');
const output = document.getElementById('output');
const bounceButton = document.getElementById('startBounce');
const fadeButton = document.getElementById('startFade');
// Запускаємо bounce анімацію
bounceButton.addEventListener('click', () => {
animatedBox.classList.remove('fade');
animatedBox.classList.add('bounce');
});
// Запускаємо fade анімацію
fadeButton.addEventListener('click', () => {
animatedBox.classList.remove('bounce');
animatedBox.classList.add('fade');
});
// Відстежуємо завершення анімації та виводимо назву анімації
animatedBox.addEventListener('animationend', (event) => {
output.textContent = `Завершено анімацію: ${event.animationName}`;
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.