回答編集履歴
1
追記
answer
CHANGED
@@ -74,4 +74,149 @@
|
|
74
74
|
<script src="http://kawama.jp/sample/js/ipop_multi.js"></script>
|
75
75
|
</body>
|
76
76
|
</html>
|
77
|
+
```
|
78
|
+
追記
|
79
|
+
---
|
80
|
+
```HTML
|
81
|
+
<!DOCTYPE html>
|
82
|
+
<html>
|
83
|
+
<head>
|
84
|
+
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
85
|
+
<meta http-equiv="content-style-type" content="text/css">
|
86
|
+
<meta http-equiv="content-script-type" content="text/javascript">
|
87
|
+
<title>jquery ipop_multi.jsのサンプル</title>
|
88
|
+
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
|
89
|
+
<script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
|
90
|
+
<script type="text/javascript">
|
91
|
+
$(function () {
|
92
|
+
$('#open1').click(function () {
|
93
|
+
$("body #open").append(
|
94
|
+
"<div class='ipop' id='mado1'>" +
|
95
|
+
"<div class='ipop_close'>×</div>" +
|
96
|
+
"<div class='ipop_title'>タイトル</div>" +
|
97
|
+
"<p>It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages</p>" +
|
98
|
+
"<div class='image'><img src='http://placehold.jp/24/cc9999/993333/150x100.png'></div>" +
|
99
|
+
"</div>"
|
100
|
+
);
|
101
|
+
$("#mado1").ipop();
|
102
|
+
});
|
103
|
+
$('#open2').click(function () {
|
104
|
+
$("body #open").append(
|
105
|
+
"<div class='ipop' id='mado2'>" +
|
106
|
+
"<div class='ipop_close'>×</div>" +
|
107
|
+
"<div class='ipop_title'>タイトル2</div>" +
|
108
|
+
"<p>It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages</p>" +
|
109
|
+
"<div class='image'><img src='http://placehold.jp/24/cc9999/993333/150x100.png'></div>" +
|
110
|
+
"</div>"
|
111
|
+
);
|
112
|
+
$("#mado2").ipop();
|
113
|
+
});
|
114
|
+
});
|
115
|
+
</script>
|
116
|
+
|
117
|
+
<style type="text/css">
|
118
|
+
.ipop {
|
119
|
+
padding: 0;
|
120
|
+
background-color: #fed;
|
121
|
+
width: 300px;
|
122
|
+
height: 200px;
|
123
|
+
border: 1px solid #aaa;
|
124
|
+
/* この3行は必須 */
|
125
|
+
position: absolute;
|
126
|
+
display: none;
|
127
|
+
z-index: 9999;
|
128
|
+
}
|
129
|
+
|
130
|
+
.ipop_title {
|
131
|
+
background-color: #fdc;
|
132
|
+
cursor: move;
|
133
|
+
}
|
134
|
+
|
135
|
+
.ipop_close {
|
136
|
+
cursor: pointer;
|
137
|
+
float: right;
|
138
|
+
}
|
139
|
+
|
140
|
+
.image {
|
141
|
+
width: 100%;
|
142
|
+
text-align: center;
|
143
|
+
}
|
144
|
+
|
145
|
+
</style>
|
146
|
+
<title>ポップアップウインドウテスト</title>
|
147
|
+
</head>
|
148
|
+
<body>
|
149
|
+
<p>Lorem Ipsum is <a href="#" id="open1">simply</a> dummy text of the printing and <a href="#"
|
150
|
+
id="open2">typesetting</a>
|
151
|
+
industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took
|
152
|
+
a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also
|
153
|
+
the leap into <a href="#" id="open3">electronic</a> typesetting, remaining essentially unchanged.
|
154
|
+
</p>
|
155
|
+
|
156
|
+
<div id="open">
|
157
|
+
|
158
|
+
</div>
|
159
|
+
<script>
|
160
|
+
|
161
|
+
(function ($) {
|
162
|
+
var ySize = 0, xSize = 0;
|
163
|
+
$.fn.ipop = function () {
|
164
|
+
|
165
|
+
var $this = $(this);
|
166
|
+
|
167
|
+
var wx, wy; // ウインドウの左上座標
|
168
|
+
var mx, my; // マウスの座標
|
169
|
+
|
170
|
+
// ウインドウの座標を画面中央にする。
|
171
|
+
wx = $(document).scrollLeft() + ($(window).width() - $(this).outerWidth()) / 2 + xSize;
|
172
|
+
if (wx < 0) wx = 0;
|
173
|
+
if ($(document).scrollLeft() + ($(window).width() - $(this).outerWidth()) <= wx) {
|
174
|
+
xSize = 0;
|
175
|
+
ySize = ySize + 50;
|
176
|
+
wx = $(document).scrollLeft() + ($(window).width() - $(this).outerWidth()) / 2 + xSize;
|
177
|
+
}
|
178
|
+
wy = $(document).scrollTop() + ($(window).height() - $(this).outerHeight()) / 2 + ySize;
|
179
|
+
if (wy < 0) wy = 0;
|
180
|
+
if ($(document).scrollTop() + ($(window).height() - $(this).outerHeight()) <= wy) {
|
181
|
+
ySize = 0;
|
182
|
+
ySize = ySize + 50;
|
183
|
+
wy = $(document).scrollTop() + ($(window).height() - $(this).outerHeight()) / 2 + ySize;
|
184
|
+
}
|
185
|
+
ySize = ySize + 50;
|
186
|
+
xSize = xSize + 50;
|
187
|
+
|
188
|
+
// ポップアップウインドウを表示する。
|
189
|
+
$this.css('top', wy).css('left', wx).fadeIn(100);
|
190
|
+
|
191
|
+
// 閉じるボタンを押したとき
|
192
|
+
$this.find('.ipop_close').click(function () {
|
193
|
+
$this.fadeOut(100);
|
194
|
+
});
|
195
|
+
|
196
|
+
// タイトルバーをドラッグしたとき
|
197
|
+
$this.find('.ipop_title').mousedown(function (e) {
|
198
|
+
mx = e.pageX;
|
199
|
+
my = e.pageY;
|
200
|
+
$(document).mousemove(mouseMove).mouseup(mouseUp);
|
201
|
+
return false;
|
202
|
+
});
|
203
|
+
function mouseMove(e) {
|
204
|
+
wx += e.pageX - mx;
|
205
|
+
wy += e.pageY - my;
|
206
|
+
$this.css('top', wy).css('left', wx);
|
207
|
+
mx = e.pageX;
|
208
|
+
my = e.pageY;
|
209
|
+
return false;
|
210
|
+
}
|
211
|
+
|
212
|
+
function mouseUp() {
|
213
|
+
$(document).unbind('mousemove', mouseMove).unbind('mouseup', mouseUp);
|
214
|
+
}
|
215
|
+
}
|
216
|
+
})
|
217
|
+
(jQuery);
|
218
|
+
|
219
|
+
</script>
|
220
|
+
</body>
|
221
|
+
</html>
|
77
222
|
```
|