-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.html
349 lines (320 loc) · 11.4 KB
/
example.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
<!doctype html><html>
<head>
<title>jQuery SameHeight Demo</title>
<meta charset="utf-8" />
<style>
body { margin: 0; padding: 0; }
body, button { font-family: Arial; font-size: 10px; }
form { margin: 0; padding: 16px 16px 16px 0; }
label { display: block; }
button:disabled { opacity: 0.5; }
h1 { margin: 0; padding: 16px; }
a { color: #00f; }
table {
width: 100%;
table-layout: fixed; /* IE11 fix to make flex calculate width correctly (but TDs does not adapt anymore) */
}
td.controls { width: 170px; }
.first-letter { font-size: 2em; }
.box { background-color: #cccccc; height: 100px; }
</style>
<style>
.target .item {
width: 50%;
margin: 16px auto;
}
.target .box .padding {
padding: 16px;
}
</style>
<style>
.float-wrapper::after {
content: ".";
visibility: hidden;
display: block;
height: 0;
clear: both;
}
.float-wrapper .item {
width: 50%;
}
.float-wrapper .float-left {
float: left;
}
.float-wrapper .item .box {
margin-left: 16px;
margin-bottom: 16px;
}
.float-wrapper .item .box .padding {
padding: 16px;
}
.float-wrapper .item:nth-child(2n) .box {
margin-right: 16px;
}
</style>
<style>
.columns-wrapper {
column-count: 2;
column-gap: 0;
margin-right: 16px;
}
.columns-wrapper .item {
width: 100%;
overflow: hidden; /* firefox and IE 10-11 */
-webkit-column-break-inside: avoid;
break-inside: avoid;
}
.columns-wrapper .item .box {
margin-left: 16px;
margin-bottom: 16px;
}
.columns-wrapper .item .box .padding {
padding: 16px;
}
</style>
<style>
.flex-wrapper {
display: flex;
flex-wrap: wrap;
align-items: flex-start;
align-content: flex-start;
}
.flex-wrapper .item {
width: 50%;
}
.flex-wrapper .item .box {
margin-left: 16px;
margin-bottom: 16px;
}
.flex-wrapper .item .box .padding {
padding: 16px;
}
</style>
</head><body>
<table border="0" cellpadding="0" cellspacing="0">
<tr valign="top">
<td class="demo">
<div class="target" id="target" style="display: none;">
<h1>target</h1>
<div class="item"><div class="box"><div class="padding">
<span class="first-letter">T</span>
lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum
</div></div></div>
</div>
<h1>float: left;</h1>
<div id="test-float" class="float-wrapper">
<div class="item float-left"><div class="box"><div class="padding">
<span class="first-letter">A</span>
lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum
</div></div></div>
<div class="item float-left"><div class="box"><div class="padding">
<span class="first-letter">B</span>
lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum
</div></div></div>
<div class="item float-left"><div class="box"><div class="padding">
<span class="first-letter">C</span>
lorem ipsum lorem ipsum lorem ipsum
</div></div></div>
</div>
<h1>column-count: 2;</h1>
<div id="test-columns" class="columns-wrapper">
<div class="item"><div class="box"><div class="padding">
<span class="first-letter">A</span>
lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum
</div></div></div>
<div class="item"><div class="box"><div class="padding">
<span class="first-letter">B</span>
lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum
</div></div></div>
<div class="item"><div class="box"><div class="padding">
<span class="first-letter">C</span>
lorem ipsum lorem ipsum lorem ipsum
</div></div></div>
</div>
<h1>display: flex;</h1>
<div id="test-flex" class="flex-wrapper">
<div class="item"><div class="box"><div class="padding">
<span class="first-letter">A</span>
lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum
</div></div></div>
<div class="item"><div class="box"><div class="padding">
<span class="first-letter">B</span>
lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum
lorem ipsum lorem ipsum lorem ipsum
</div></div></div>
<div class="item"><div class="box"><div class="padding">
<span class="first-letter">C</span>
lorem ipsum lorem ipsum lorem ipsum
</div></div></div>
</div>
</td>
<td class="controls" nowrap>
<form>
<b><a href="https://github.com/giorgiobeggiora/jquery-sameheight" target="_blank" rel="noopener">JQUERY SAME HEIGHT</a></b><br />
<br />
<button id="btn-observe">OBSERVE</button>
<button id="btn-stop">STOP</button><br />
<br />
<b>OPTIONS</b><br />
<br />
The first value is the default one.<br />
<br />
<br />
<b>observe</b><br />
<label title="window"><input type="radio" name="observe" value="window" /> Observe window</label>
<label title="body"><input type="radio" name="observe" value="body" /> Observe body</label>
<br />
<b>debounce</b><br />
<label title="0"><input type="radio" name="debounce" value="0" /> 0ms</label>
<label title="250"><input type="radio" name="debounce" value="250" /> 250ms</label>
<br />
<b>responsive</b><br />
<label title="true"><input type="radio" name="responsive" value="true" /> ignore element's CSS height</label>
<label title="false"><input type="radio" name="responsive" value="false" /> consider element's CSS height</label>
<br />
<b>compact</b><br />
<label title="false"><input type="radio" name="compact" value="false" /> each row has the same height</label>
<label title="true"><input type="radio" name="compact" value="true" /> each row has its own height</label>
<br />
<b>target</b><br />
<label title="null"><input type="radio" name="target" value="null" /> matched elements</label>
<label title="document.getElementById('target')"><input type="radio" name="target" value="target" /> target element</label>
<br />
<b>columnCount</b><br />
<label title="1"><input type="radio" name="columnCount" value="1" /> 1</label>
<label title="num"><input type="radio" name="columnCount" value="num" /> (number)</label>
<label title="calc"><input type="radio" name="columnCount" value="calc" /> calc</label>
</form>
</td>
</tr>
</table>
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/css-element-queries/1.0.2/ResizeSensor.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/css-element-queries/1.0.2/ElementQueries.js"></script> -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="jquery.sameheight.js"></script>
<script>
var options = {
compact: false,
responsive: true,
target: null,
observe: window,
debounce: 0,
columnCount: 'num'
};
function convertToOptionsValue (key, value) {
switch (key) {
case 'compact': return value === 'true' ; break;
case 'responsive': return value === 'true' ; break;
case 'observe': return value === 'window' ? window : document.body ; break;
case 'debounce': return value === '250' ? Number(value) : 0 ; break;
case 'target': return value === 'target' ? $('#target .box') : null; break;
case 'columnCount': return ['calc','num','1'].indexOf(value) !== -1 ? value : 'num'; break;
default: return void 0; break;
}
}
function convertToQueryValue (key, value) {
switch (key) {
case 'compact': return String(value); break;
case 'responsive': return String(value); break;
case 'observe': return value === window ? 'window' : 'body' ; break;
case 'debounce': return String(value); break;
case 'target': return value === null ? 'null' : 'target' ; break;
case 'columnCount': return String(value); break;
default: return void 0; break;
}
}
var queryEntries = location.search.match(/(?:[^\&\?])+/g) || [];
queryEntries.forEach(function(entry){
var param = entry.split('=');
var key = param[0], value = convertToOptionsValue(key, param[1]);
if (value !== void 0) options[key] = value;
});
Object.keys(options).forEach(function(key){
var value = convertToQueryValue(key, options[key]);
if (value !== void 0) $('input[name="' + key + '"][value="' + value + '"]').prop('checked', true);
});
function reloadWithOptions(ev) {
var key = ev.target.name, value = convertToOptionsValue(key, ev.target.value);
if (value !== void 0) options[key] = value;
var queryString = Object.keys(options).map(function(key){
return key + '=' + convertToQueryValue(key, options[key]);
}).join("&");
location.href = location.pathname + '?' + queryString;
}
$('input[name="observe"]').on('click', reloadWithOptions);
$('input[name="debounce"]').on('click', reloadWithOptions);
$('input[name="responsive"]').on('click', reloadWithOptions);
$('input[name="compact"]').on('click', reloadWithOptions);
$('input[name="target"]').on('click', reloadWithOptions);
$('input[name="columnCount"]').on('click', reloadWithOptions);
$('#btn-observe').on('click', startObserve);
$('#btn-stop').on('click', stopObserve);
if (options.target) $('#target').show();
var columnCount;
var handler0;
var handler1;
var handler2;
function startObserve(ev) {
if (ev) ev.preventDefault();
$('#btn-observe').prop('disabled', true);
$('#btn-stop').prop('disabled', false);
columnCount = options.columnCount;
if (columnCount === 'num') columnCount = 1;
handler0 = $('#test-float .item .box').sameHeight({
compact: options.compact,
responsive: options.responsive,
target: options.target,
observe: options.observe,
debounce: options.debounce,
columnCount: columnCount
});
columnCount = options.columnCount;
if (columnCount === 'num') columnCount = $('.columns-wrapper').css('column-count');
handler1 = $('#test-columns .item .box').sameHeight({
compact: options.compact,
responsive: options.responsive,
target: options.target,
observe: options.observe,
debounce: options.debounce,
columnCount: columnCount
});
columnCount = options.columnCount;
if (columnCount === 'num') columnCount = 1;
handler2 = $('#test-flex .item .box').sameHeight({
compact: options.compact,
responsive: options.responsive,
target: options.target,
observe: options.observe,
debounce: options.debounce,
columnCount: columnCount
});
}
function stopObserve(ev) {
if (ev) ev.preventDefault();
$('#btn-observe').prop('disabled', false);
$('#btn-stop').prop('disabled', true);
handler0.stop();
handler1.stop();
handler2.stop();
}
startObserve();
</script>
</body></html>