teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

a

2020/01/04 18:46

投稿

KazuSaka
KazuSaka

スコア640

answer CHANGED
@@ -1,2 +1,91 @@
1
1
  ボタンを中心に広がるアニメーション部分のみ作ってみました。
2
- [コードペン](https://codepen.io/KazuSaka/pen/dyPZLBV)
2
+ [コードペン](https://codepen.io/KazuSaka/pen/dyPZLBV)
3
+
4
+ 以下コード。
5
+ ```html
6
+ <!DOCTYPE html>
7
+ <html>
8
+ <head>
9
+ <meta charset="utf-8">
10
+ <meta name="viewport" content="width=device-width">
11
+ <link href="style.css" rel="stylesheet">
12
+ <title>JS Bin</title>
13
+ </head>
14
+ <body>
15
+ <div class="wrap">
16
+ <button id="back-button"></button><!-- ボタンの背後に配置(中心から徐々に大きくする用) -->
17
+ <button id="front-button" onmousedown="down();" onmouseup="up();">change</button>
18
+ </div>
19
+ </body>
20
+ </html>
21
+
22
+
23
+ <script type="text/javascript">
24
+ var eb = document.getElementById("back-button"); //ボタンの背後
25
+ var ef = document.getElementById("front-button"); //ボタン自体
26
+ var down = function() {
27
+ eb.style.display = "block"; //ボタンの背後の要素を表示
28
+ eb.style.animation = "animation 2s ease";
29
+ ef.style.background = "white";
30
+ ef.style.color = "tomato";
31
+ ef.style.transition = "2s";
32
+ }
33
+
34
+ var up = function() {
35
+ eb.style.animation = "animation2 2s ease";
36
+ eb.style.display = "none"; //ボタンの背後を非表示
37
+ ef.style.background = "tomato"; //ボタンの色を戻す
38
+ ef.style.color = "white"; //ボタンの色を戻す
39
+ }
40
+ </script>
41
+
42
+ ```
43
+
44
+ ```css
45
+ body {
46
+ width: 100vw;
47
+ height: 100vh;
48
+ }
49
+ .wrap{
50
+ position: relative;
51
+ width: 70px;
52
+ height: 70px;
53
+ }
54
+ button{
55
+ position: absolute;
56
+ top: 0;
57
+ left: 0;
58
+ color: white;
59
+ background: tomato;
60
+ border: none;
61
+ border-radius: 50%;
62
+ width: 70px;
63
+ height: 70px;
64
+ }
65
+ #back-button{
66
+ display: none;
67
+ position: absolute;
68
+ top:50%;
69
+ left:50%;
70
+ transform: translate(-50%, -50%);
71
+ color: black;
72
+ background: red;
73
+ border: none;
74
+ border-radius: 50%;
75
+ width: 5000px;
76
+ height: 5000px;
77
+ padding:0;
78
+ }
79
+
80
+ @keyframes animation {
81
+ 0% {
82
+ width: 0%;
83
+ height: 0%;
84
+ }
85
+ 100% {
86
+ width: 5000px;
87
+ height:5000px;
88
+ }
89
+ }
90
+
91
+ ```