2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

クリックを押すタイミング毎にclassをつけたり消したりする

Last updated at Posted at 2019-05-05

JavaScriptについて学び

本日端午の節句。Qiitaを始めてみました。

HTML

<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>JavaScript Click Event</title>
</head>
<body>
  <div class="wrapper">
    <div id="target" class="parallelogram">
    </div>
  </div>
  <script src="js/main.js"></script>
</body>
</html>

main.js

<script>
'use strict';

const target = document.getElementById('target');
// document.getElementById('target')を定数(const)にtargetとして代入

target.addEventListener('click', function() {
  target.classList.toggle('circle');

});

</script>

style.css

.wrapper {
      padding-top: 600px;
      position: relative;
    }

    .parallelogram {

      width: 100px;
      height: 100px;
      background: #43676b;
      /* 御召茶 */
      cursor: pointer;
      transition: 0.8s;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%) skew(20deg);
    }


    .circle {
      border-radius: 50%;
      background: #aa4c8f;
      /* 梅紫 */
      transform: translate(-50%, -50%) rotate(360deg);
    }
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?