質問編集履歴

2

class名を修正

2019/11/11 07:08

投稿

soda346
soda346

スコア18

test CHANGED
File without changes
test CHANGED
@@ -142,7 +142,7 @@
142
142
 
143
143
  var pictContainer = document.querySelector('#pict-container');
144
144
 
145
- var xBtn = document.querySelectorAll(".btn-flat-border")[0];
145
+ var xBtn = document.querySelectorAll(".xbtn")[0];
146
146
 
147
147
 
148
148
 

1

JavaScriptのコードを追加しました

2019/11/11 07:08

投稿

soda346
soda346

スコア18

test CHANGED
File without changes
test CHANGED
@@ -119,3 +119,105 @@
119
119
  }
120
120
 
121
121
  ```
122
+
123
+
124
+
125
+ ```JavaScript
126
+
127
+ (function() {
128
+
129
+ var picts = document.querySelectorAll('.gallery');
130
+
131
+ var srcs = Array.from(picts).map(function(pict) {
132
+
133
+ return pict.parentNode.href;
134
+
135
+ });
136
+
137
+
138
+
139
+ var modal = document.querySelector('#modal');
140
+
141
+ var modalContent = document.querySelectorAll('.modal-content')[0];
142
+
143
+ var pictContainer = document.querySelector('#pict-container');
144
+
145
+ var xBtn = document.querySelectorAll(".btn-flat-border")[0];
146
+
147
+
148
+
149
+ xBtn.addEventListener('click', function(e) {
150
+
151
+ e.preventDefault();
152
+
153
+ modal.style.display = 'none';
154
+
155
+ });
156
+
157
+
158
+
159
+ picts.forEach(function(pict) {
160
+
161
+ pict.addEventListener('click', function(e) {
162
+
163
+ e.preventDefault();
164
+
165
+ var aEle = e.target.parentNode;
166
+
167
+ // modal.style.display = 'block';
168
+
169
+ modal.style.display = 'flex';
170
+
171
+ modal.style.justifyConten = 'center';
172
+
173
+ modal.style.alignItems = 'center';
174
+
175
+ pictContainer.style.width = "80%";
176
+
177
+ pictContainer.style.height = "90%";
178
+
179
+ pictContainer.firstChild.src = aEle.href;
180
+
181
+
182
+
183
+ pictContainer.firstChild.height = window.innerHeight * 0.9;
184
+
185
+ pictContainer.firstChild.width = pictContainer.firstChild.height * 1.31;
186
+
187
+ pictContainer.style.textAlign = 'center';
188
+
189
+
190
+
191
+ pictContainer.addEventListener('click', function(e) {
192
+
193
+ var idx = srcs.indexOf(pictContainer.firstChild.src);
194
+
195
+ pictContainer.firstChild.src = (srcs[idx + 1]) ? srcs[idx + 1] : srcs[0];
196
+
197
+ });
198
+
199
+ // modalContent.width = pictContainer.firstChild.width;
200
+
201
+ // modalContent.height = pictContainer.firstChild.height;
202
+
203
+
204
+
205
+ });
206
+
207
+ });
208
+
209
+
210
+
211
+ window.addEventListener('click', function(e) {
212
+
213
+ if (e.target === modal) {
214
+
215
+ modal.style.display = 'none';
216
+
217
+ }
218
+
219
+ });
220
+
221
+ })();
222
+
223
+ ```