作品一覧に戻る
呪いを外から掛ける

呪いを外から掛ける

秋山宗太郎 04/03 15:32
アプリを動かす
コードを見る
<button id="castBtn">呪いをかけろ</button>
<div id="box"></div>
<button id="removeBtn">呪いを解け</button>
#box {
  width: 100px;
  height: 100px;
  background: steelblue;
  margin-top: 16px;
}

.animated {
  animation: henshin 1s infinite alternate;
}

@keyframes henshin {
  from {
    background: steelblue;
    transform: scale(1);
  }
  to {
    background: tomato;
    transform: scale(1.5);
  }
}
const btn = document.querySelector('#castBtn');
const box = document.querySelector('#box');

btn.addEventListener('click', function() {
  box.classList.add('animated');
});
const removeBtn = document.querySelector('#removeBtn');

removeBtn.addEventListener('click', function() {
  box.classList.remove('animated');
});