質問編集履歴

1

コードを追記、タイトル変更

2019/05/05 04:04

投稿

myc
myc

スコア18

test CHANGED
@@ -1 +1 @@
1
- iOSでクリックイベントが発しない
1
+ addEventListener登録したクリックイベントがiOSでしない
test CHANGED
@@ -16,6 +16,198 @@
16
16
 
17
17
 
18
18
 
19
+ ```html
20
+
21
+ <button id="openModal">Open modal</button>
22
+
23
+
24
+
25
+ <section id="modalArea" class="modalArea">
26
+
27
+ <div id="modalBg" class="modalBg"></div>
28
+
29
+ <div class="modalWrapper">
30
+
31
+ <div class="modalContents">
32
+
33
+ <h1>Here are modal without jQuery!</h1>
34
+
35
+ <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p>
36
+
37
+ </div>
38
+
39
+ <div id="closeModal" class="closeModal">
40
+
41
+ ×
42
+
43
+ </div>
44
+
45
+ </div>
46
+
47
+ </section>
48
+
49
+ ```
50
+
51
+ ```css
52
+
53
+ * {
54
+
55
+ box-sizing: border-box;
56
+
57
+ }
58
+
59
+ body {
60
+
61
+ font-family:'Avenir','Helvetica, Neue','Helvetica','Arial';
62
+
63
+ }
64
+
65
+
66
+
67
+ .modalArea {
68
+
69
+ visibility: hidden;
70
+
71
+ opacity : 0;
72
+
73
+ position: fixed;
74
+
75
+ z-index: 10;
76
+
77
+ top: 0;
78
+
79
+ left: 0;
80
+
81
+ width: 100%;
82
+
83
+ height: 100%;
84
+
85
+ transition: .4s;
86
+
87
+ }
88
+
89
+
90
+
91
+ .modalBg {
92
+
93
+ width: 100%;
94
+
95
+ height: 100%;
96
+
97
+ background-color: rgba(30,30,30,0.9);
98
+
99
+ }
100
+
101
+
102
+
103
+ .modalWrapper {
104
+
105
+ position: absolute;
106
+
107
+ top: 50%;
108
+
109
+ left: 50%;
110
+
111
+ transform:translate(-50%,-50%);
112
+
113
+ width: 70%;
114
+
115
+ max-width: 500px;
116
+
117
+ padding: 10px 30px;
118
+
119
+ background-color: #fff;
120
+
121
+ }
122
+
123
+
124
+
125
+ .closeModal {
126
+
127
+ position: absolute;
128
+
129
+ top: 0.5rem;
130
+
131
+ right: 1rem;
132
+
133
+ cursor: pointer;
134
+
135
+ }
136
+
137
+
138
+
139
+ .is-show {
140
+
141
+ visibility: visible;
142
+
143
+ opacity : 1;
144
+
145
+ }
146
+
147
+
148
+
149
+ button {
150
+
151
+ padding: 10px;
152
+
153
+ background-color: #fff;
154
+
155
+ border: 1px solid #282828;
156
+
157
+ border-radius: 2px;
158
+
159
+ cursor: pointer;
160
+
161
+ }
162
+
163
+
164
+
165
+ #openModal {
166
+
167
+ position: absolute;
168
+
169
+ top: 50%;
170
+
171
+ left: 50%;
172
+
173
+ transform:translate(-50%,-50%);
174
+
175
+ }
176
+
177
+ ```
178
+
179
+ ```js
180
+
181
+ (function () {
182
+
183
+ const modalArea = document.getElementById('modalArea');
184
+
185
+ const openModal = document.getElementById('openModal');
186
+
187
+ const closeModal = document.getElementById('closeModal');
188
+
189
+ const modalBg = document.getElementById('modalBg');
190
+
191
+ const toggle = [openModal,closeModal,modalBg];
192
+
193
+
194
+
195
+ for(let i=0, len=toggle.length ; i<len ; i++){
196
+
197
+ toggle[i].addEventListener('click',function(){
198
+
199
+ modalArea.classList.toggle('is-show');
200
+
201
+ },false);
202
+
203
+ }
204
+
205
+ }());
206
+
207
+ ```
208
+
209
+
210
+
19
211
  ### 試したこと
20
212
 
21
213