LoginSignup
0
1

More than 3 years have passed since last update.

JavaScriptで勉強時間を伸ばすボタン作ってみた!

Posted at

休憩したくなったら押すだけです!

永遠と「休憩」がでなければ、ひたすら勉強できますよ笑

Screen Recording 2020-11-22 at 03.46 PM.gif

index.html
<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="UTF-8" />
    <title>GAME</title>
    <link rel="stylesheet" href="css/styles.css">
  </head>
  <body>
    <h1>押してね!</h1>
    <div id="btn">?</div>
    <script src="js/main.js"></script>
  </body>
</html>
styles.css
h1 {
  text-align: center;
}

body {
  background: #efefef;
}

#btn {
  width: 200px;
  height: 200px;
  background: #ef454a;
  border-radius: 30%;
  margin: 30px auto;
  text-align: center;
  line-height: 200px;
  color: white;
  font-weight: bold;
  font-size: 42px;
  cursor: pointer;
  box-shadow: 0 10px 0 #d1483e;
  user-select: none;
}

#btn:hover {
  opacity: 0.9;
}

#btn:active {
  box-shadow: 0 5px 0 #d1483e;
  margin-top: 40px;
}
main.js
'use strict';

{
  const btn = document.getElementById('btn');
 
  btn.addEventListener('click', () => {
    const n = Math.floor(Math.random() * 3);

    switch (n) {
      case 0:
        btn.textContent = '休憩';
        break;
      case 1:
        btn.textContent = 'もう10分';
        break;
      case 2:
        btn.textContent = 'もう15分';
        break;
    }
  })
}

JavaScriptほんと楽しい(^^)

参考

JavaScriptでおみくじを作ろう

0
1
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
0
1