<header>
  <h2 class="title">element.style.animationName</h2>
  <p class="description">Встановлює або повертає назву анімації для елемента.</p>
</header>
<main>
  <div class="result">
    <div class="box"></div>
    <div class="controls">
      <button id="startAnimation">Запустити анімацію</button>
      <button id="stopAnimation">Зупинити анімацію</button>
      <select id="animationSelect">
        <option value="slideIn">Вхід зліва</option>
        <option value="slideOut">Вихід справа</option>
        <option value="fadeIn">Поява</option>
        <option value="fadeOut">Зникнення</option>
      </select>
    </div>
  </div>
</main>
body {
  font-size: 16px;
  line-height: 1.5;
  font-family: monospace;
}

header {
  background-color: #f1f1f1;
  margin-bottom: 25px;
  padding: 15px;
  -webkit-box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
  -moz-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;
  -webkit-box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
  -moz-box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
  box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
}

.box {
  width: 100px;
  height: 100px;
  background-color: #333;
  animation-duration: 1s;
  animation-fill-mode: forwards;
}

@keyframes slideIn {
  from { transform: translateX(-100%); }
  to { transform: translateX(0); }
}

@keyframes slideOut {
  from { transform: translateX(0); }
  to { transform: translateX(100%); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}
const box = document.querySelector('.box');
const startButton = document.getElementById('startAnimation');
const stopButton = document.getElementById('stopAnimation');
const animationSelect = document.getElementById('animationSelect');

let animationRunning = false;

startButton.addEventListener('click', () => {
  if (!animationRunning) {
    const animationName = animationSelect.value;
    box.style.animationName = animationName;
    animationRunning = true;
  }
});

stopButton.addEventListener('click', () => {
  box.style.animationName = 'none';
  animationRunning = false;
});

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.