回答編集履歴

1

追記

2016/12/26 09:29

投稿

s8_chu
s8_chu

スコア14731

test CHANGED
@@ -151,3 +151,293 @@
151
151
  </html>
152
152
 
153
153
  ```
154
+
155
+ 追記
156
+
157
+ ---
158
+
159
+ ```HTML
160
+
161
+ <!DOCTYPE html>
162
+
163
+ <html>
164
+
165
+ <head>
166
+
167
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
168
+
169
+ <meta http-equiv="content-style-type" content="text/css">
170
+
171
+ <meta http-equiv="content-script-type" content="text/javascript">
172
+
173
+ <title>jquery ipop_multi.jsのサンプル</title>
174
+
175
+ <script type="text/javascript" src="http://www.google.com/jsapi"></script>
176
+
177
+ <script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
178
+
179
+ <script type="text/javascript">
180
+
181
+ $(function () {
182
+
183
+ $('#open1').click(function () {
184
+
185
+ $("body #open").append(
186
+
187
+ "<div class='ipop' id='mado1'>" +
188
+
189
+ "<div class='ipop_close'>×</div>" +
190
+
191
+ "<div class='ipop_title'>タイトル</div>" +
192
+
193
+ "<p>It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages</p>" +
194
+
195
+ "<div class='image'><img src='http://placehold.jp/24/cc9999/993333/150x100.png'></div>" +
196
+
197
+ "</div>"
198
+
199
+ );
200
+
201
+ $("#mado1").ipop();
202
+
203
+ });
204
+
205
+ $('#open2').click(function () {
206
+
207
+ $("body #open").append(
208
+
209
+ "<div class='ipop' id='mado2'>" +
210
+
211
+ "<div class='ipop_close'>×</div>" +
212
+
213
+ "<div class='ipop_title'>タイトル2</div>" +
214
+
215
+ "<p>It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages</p>" +
216
+
217
+ "<div class='image'><img src='http://placehold.jp/24/cc9999/993333/150x100.png'></div>" +
218
+
219
+ "</div>"
220
+
221
+ );
222
+
223
+ $("#mado2").ipop();
224
+
225
+ });
226
+
227
+ });
228
+
229
+ </script>
230
+
231
+
232
+
233
+ <style type="text/css">
234
+
235
+ .ipop {
236
+
237
+ padding: 0;
238
+
239
+ background-color: #fed;
240
+
241
+ width: 300px;
242
+
243
+ height: 200px;
244
+
245
+ border: 1px solid #aaa;
246
+
247
+ /* この3行は必須 */
248
+
249
+ position: absolute;
250
+
251
+ display: none;
252
+
253
+ z-index: 9999;
254
+
255
+ }
256
+
257
+
258
+
259
+ .ipop_title {
260
+
261
+ background-color: #fdc;
262
+
263
+ cursor: move;
264
+
265
+ }
266
+
267
+
268
+
269
+ .ipop_close {
270
+
271
+ cursor: pointer;
272
+
273
+ float: right;
274
+
275
+ }
276
+
277
+
278
+
279
+ .image {
280
+
281
+ width: 100%;
282
+
283
+ text-align: center;
284
+
285
+ }
286
+
287
+
288
+
289
+ </style>
290
+
291
+ <title>ポップアップウインドウテスト</title>
292
+
293
+ </head>
294
+
295
+ <body>
296
+
297
+ <p>Lorem Ipsum is <a href="#" id="open1">simply</a> dummy text of the printing and <a href="#"
298
+
299
+ id="open2">typesetting</a>
300
+
301
+ industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took
302
+
303
+ a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also
304
+
305
+ the leap into <a href="#" id="open3">electronic</a> typesetting, remaining essentially unchanged.
306
+
307
+ </p>
308
+
309
+
310
+
311
+ <div id="open">
312
+
313
+
314
+
315
+ </div>
316
+
317
+ <script>
318
+
319
+
320
+
321
+ (function ($) {
322
+
323
+ var ySize = 0, xSize = 0;
324
+
325
+ $.fn.ipop = function () {
326
+
327
+
328
+
329
+ var $this = $(this);
330
+
331
+
332
+
333
+ var wx, wy; // ウインドウの左上座標
334
+
335
+ var mx, my; // マウスの座標
336
+
337
+
338
+
339
+ // ウインドウの座標を画面中央にする。
340
+
341
+ wx = $(document).scrollLeft() + ($(window).width() - $(this).outerWidth()) / 2 + xSize;
342
+
343
+ if (wx < 0) wx = 0;
344
+
345
+ if ($(document).scrollLeft() + ($(window).width() - $(this).outerWidth()) <= wx) {
346
+
347
+ xSize = 0;
348
+
349
+ ySize = ySize + 50;
350
+
351
+ wx = $(document).scrollLeft() + ($(window).width() - $(this).outerWidth()) / 2 + xSize;
352
+
353
+ }
354
+
355
+ wy = $(document).scrollTop() + ($(window).height() - $(this).outerHeight()) / 2 + ySize;
356
+
357
+ if (wy < 0) wy = 0;
358
+
359
+ if ($(document).scrollTop() + ($(window).height() - $(this).outerHeight()) <= wy) {
360
+
361
+ ySize = 0;
362
+
363
+ ySize = ySize + 50;
364
+
365
+ wy = $(document).scrollTop() + ($(window).height() - $(this).outerHeight()) / 2 + ySize;
366
+
367
+ }
368
+
369
+ ySize = ySize + 50;
370
+
371
+ xSize = xSize + 50;
372
+
373
+
374
+
375
+ // ポップアップウインドウを表示する。
376
+
377
+ $this.css('top', wy).css('left', wx).fadeIn(100);
378
+
379
+
380
+
381
+ // 閉じるボタンを押したとき
382
+
383
+ $this.find('.ipop_close').click(function () {
384
+
385
+ $this.fadeOut(100);
386
+
387
+ });
388
+
389
+
390
+
391
+ // タイトルバーをドラッグしたとき
392
+
393
+ $this.find('.ipop_title').mousedown(function (e) {
394
+
395
+ mx = e.pageX;
396
+
397
+ my = e.pageY;
398
+
399
+ $(document).mousemove(mouseMove).mouseup(mouseUp);
400
+
401
+ return false;
402
+
403
+ });
404
+
405
+ function mouseMove(e) {
406
+
407
+ wx += e.pageX - mx;
408
+
409
+ wy += e.pageY - my;
410
+
411
+ $this.css('top', wy).css('left', wx);
412
+
413
+ mx = e.pageX;
414
+
415
+ my = e.pageY;
416
+
417
+ return false;
418
+
419
+ }
420
+
421
+
422
+
423
+ function mouseUp() {
424
+
425
+ $(document).unbind('mousemove', mouseMove).unbind('mouseup', mouseUp);
426
+
427
+ }
428
+
429
+ }
430
+
431
+ })
432
+
433
+ (jQuery);
434
+
435
+
436
+
437
+ </script>
438
+
439
+ </body>
440
+
441
+ </html>
442
+
443
+ ```