-
Notifications
You must be signed in to change notification settings - Fork 4
/
cross-browser.html
350 lines (333 loc) · 16.9 KB
/
cross-browser.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
350
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Floatery - A CSS Only Masonry Layout!!!</title>
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Roboto+Slab:400,300,700&subset=latin,cyrillic-ext" />
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html, body {
width: 100%;
height: 100%;
}
html {
font-size: 100%;
font-family: "Roboto Slab", serif;
height: 100%;
}
body {
line-height: 25px;
height: 100%;
background-color: #e9e9e9;
}
img {
max-width: 100%;
}
.container {
margin: 10px;
position: relative;
height: 100%;
}
.row {
padding: 5px 20px;
margin: 0 -20px;
}
.container:after,
.row:after {
content: '';
display: table;
clear: both;
}
.floaters {
display: inline-block;
vertical-align: top;
width: 33.333333333333%;
}
.floaters > .box {
margin: 5px;
border: 1px solid #dedede;
padding: 15px;
vertical-align: top;
background-color: #fff;
color: #333;
}
.imp {
width: 50%;
background-color: #333;
color: silver;
}
#container:after {
content: ".";
visibility: hidden;
display: block;
height: 0;
clear: both;
}
</style>
</head>
<body>
<div class="container" id="container">
<div class="row">
<div class="floaters">
<div class="box">
<h3>Some title 1</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Velit sapiente eveniet alias numquam, provident, aperiam repudiandae quasi voluptatibus a ex minus, explicabo ad id dolore perferendis maxime earum beatae. Error quos reiciendis minus.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Velit sapiente eveniet alias numquam, provident, aperiam repudiandae quasi voluptatibus a ex minus, explicabo ad id dolore perferendis maxime earum beatae. Error quos reiciendis minus.</p>
</div>
</div><div class="floaters">
<div class="box">
<h3>Some title 2</h3>
<img src="http://lorempixel.com/600/450?p=2" alt="cat image" alt="" />
<p>Suscipit eveniet voluptatibus maxime minima fugit totam, sit asperiores numquam. Minus ratione, inventore. Labore est tenetur enim nostrum animi incidunt, sed hic alias consectetur ad laudantium sunt fugit quia, minima vel nemo. Repellendus.</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptates veniam similique ad quidem, et, magni velit quos possimus, illo illum repellat laudantium iusto totam qui? Facere ad, enim at sit.
</p>
</div>
</div><div class="floaters">
<div class="box">
<h3>Some title 3</h3>
<p>Deleniti modi nulla quibusdam delectus dolorum at soluta velit illum quisquam quasi consequuntur voluptatibus distinctio, fuga cum enim, dolore perferendis sed corrupti officiis eos veniam et temporibus impedit eveniet. Expedita possimus unde nisi.</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Impedit dolorum exercitationem blanditiis recusandae quo, accusantium temporibus modi dolores labore tenetur hic, quam fugiat sapiente unde iusto animi alias deserunt sint.
</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Minus id odio, voluptatum autem illum.</p>
</div>
</div><div class="floaters">
<div class="box">
<h3>Some title 4</h3>
<p>Error, voluptas, laborum. Obcaecati debitis minima nostrum similique voluptates expedita fuga sit aliquid ad dolorem placeat harum, inventore voluptas ex autem fugiat, quia laborum dolores facere necessitatibus illum in commodi velit unde! A?</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Pariatur, saepe et dignissimos impedit ex, inventore rerum facere dicta excepturi harum commodi soluta quod repellendus fugiat sapiente quisquam rem molestiae recusandae.
</p>
</div>
</div><div class="floaters">
<div class="box">
<h3>Some title 5</h3>
<img src="http://lorempixel.com/600/450?p=5" alt="cat image" alt="" />
<p>Obcaecati ex eum illo ea id reiciendis molestias ullam mollitia, minima, aspernatur pariatur, adipisci ipsum architecto necessitatibus tempore laudantium aliquam! Voluptatum quas placeat, non aliquam hic porro ex sint deserunt nisi quos ipsa.</p>
</div>
</div><div class="floaters">
<div class="box">
<h3>Some title 6</h3>
<img src="http://lorempixel.com/600/450?p=6" alt="cat image" alt="" />
<p>Quasi eos magni labore repellendus architecto eligendi officiis, eveniet fuga recusandae, nemo dignissimos quam. Accusantium sapiente dolorum ex quisquam, consequatur repellendus dolor, alias adipisci labore rem ut fugit aperiam doloremque, amet non voluptas!</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ratione esse sed eligendi, laudantium voluptas, fugit sint ea quibusdam, autem blanditiis commodi molestias, aperiam quas! Autem consequuntur neque, repudiandae commodi pariatur!
</p>
</div>
</div><div class="floaters">
<div class="box">
<h3>Some title 7</h3>
<img src="http://lorempixel.com/600/450?p=7" alt="cat image" alt="" />
<p>Aliquid quod, placeat delectus nemo magni itaque amet nam ad iste dolorem, repellat possimus dolorum nisi, consequuntur neque, quas. Quia dolor adipisci delectus doloremque, officiis reiciendis quod voluptate cupiditate, aliquid maxime cum, doloribus!</p>
</div>
</div><div class="floaters">
<div class="box">
<h3>Some title 8</h3>
<p>Labore animi illo eveniet aliquam est, accusamus saepe obcaecati provident omnis esse repellat atque optio sequi, voluptate nesciunt expedita maxime! Dolorum ipsam corporis laboriosam eveniet aut quas? Temporibus repudiandae, est autem aspernatur optio!</p>
</div>
</div><div class="floaters">
<div class="box">
<h3>Some title 9</h3>
<img src="http://lorempixel.com/600/450?p=9" alt="cat image" alt="" />
<p>Commodi fuga impedit, iure quia unde! Quas sit eligendi, totam optio quidem sapiente molestiae delectus qui voluptates amet! Ratione voluptas molestias ea iusto pariatur ullam repudiandae enim alias perferendis nemo, omnis, aliquam adipisci?</p>
</div>
</div><div class="floaters">
<div class="box">
<h3>Some title 10</h3>
<p>Iure assumenda perspiciatis omnis minima beatae ea architecto sequi quisquam dolores maxime numquam voluptates at unde reiciendis, atque et ullam minus distinctio modi! Necessitatibus nihil pariatur eos officia consequuntur similique illum vero hic!</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quod vero perferendis quasi molestiae recusandae soluta sint necessitatibus quos facere obcaecati dolores modi illum, fugit incidunt, id. Non soluta maiores doloremque.
</p>
</div>
</div><div class="floaters">
<div class="box">
<h3>Some title 11</h3>
<img src="http://lorempixel.com/600/450?p=11" alt="cat image" alt="" />
<p>Labore animi illo eveniet aliquam est, accusamus saepe obcaecati provident omnis esse repellat atque optio sequi, voluptate nesciunt expedita maxime! Dolorum ipsam corporis laboriosam eveniet aut quas? Temporibus repudiandae, est autem aspernatur optio!</p>
</div>
</div><div class="floaters">
<div class="box">
<h3>Some title 12</h3>
<p>Error, voluptas, laborum. Obcaecati debitis minima nostrum similique voluptates expedita fuga sit aliquid ad dolorem placeat harum, inventore voluptas ex autem fugiat, quia laborum dolores facere necessitatibus illum in commodi velit unde! A?</p>
</div>
</div><div class="floaters">
<div class="box">
<h3>Some title 13</h3>
<img src="http://lorempixel.com/600/450?p=13" alt="cat image" alt="" />
<p>Aliquid quod, placeat delectus nemo magni itaque amet nam ad iste dolorem, repellat possimus dolorum nisi, consequuntur neque, quas. Quia dolor adipisci delectus doloremque, officiis reiciendis quod voluptate cupiditate, aliquid maxime cum, doloribus!</p>
</div>
</div><div class="floaters">
<div class="box">
<h3>Some title 14</h3>
<p>Labore animi illo eveniet aliquam est, accusamus saepe obcaecati provident omnis esse repellat atque optio sequi, voluptate nesciunt expedita maxime! Dolorum ipsam corporis laboriosam eveniet aut quas? Temporibus repudiandae, est autem aspernatur optio!</p>
</div>
</div><div class="floaters">
<div class="box">
<h3>Some title 15</h3>
<img src="http://lorempixel.com/600/450?p=15" alt="cat image" alt="" />
<p>Commodi fuga impedit, iure quia unde! Quas sit eligendi, totam optio quidem sapiente molestiae delectus qui voluptates amet! Ratione voluptas molestias ea iusto pariatur ullam repudiandae enim alias perferendis nemo, omnis, aliquam adipisci?</p>
</div>
</div><div class="floaters">
<div class="box">
<h3>Some title 16</h3>
<p>Iure assumenda perspiciatis omnis minima beatae ea architecto sequi quisquam dolores maxime numquam voluptates at unde reiciendis, atque et ullam minus distinctio modi! Necessitatibus nihil pariatur eos officia consequuntur similique illum vero hic!</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quod vero perferendis quasi molestiae recusandae soluta sint necessitatibus quos facere obcaecati dolores modi illum, fugit incidunt, id. Non soluta maiores doloremque.
</p>
</div>
</div><div class="floaters">
<div class="box">
<h3>Some title 17</h3>
<img src="http://lorempixel.com/600/450?p=13" alt="cat image" alt="" />
<p>Labore animi illo eveniet aliquam est, accusamus saepe obcaecati provident omnis esse repellat atque optio sequi, voluptate nesciunt expedita maxime! Dolorum ipsam corporis laboriosam eveniet aut quas? Temporibus repudiandae, est autem aspernatur optio!</p>
</div>
</div><div class="floaters">
<div class="box">
<h3>Some title 18</h3>
<p>Error, voluptas, laborum. Obcaecati debitis minima nostrum similique voluptates expedita fuga sit aliquid ad dolorem placeat harum, inventore voluptas ex autem fugiat, quia laborum dolores facere necessitatibus illum in commodi velit unde! A?</p>
</div>
</div><div class="floaters">
<div class="box">
<h3>Some title 19</h3>
<img src="http://lorempixel.com/600/450?p=19" alt="cat image" alt="" />
<p>Aliquid quod, placeat delectus nemo magni itaque amet nam ad iste dolorem, repellat possimus dolorum nisi, consequuntur neque, quas. Quia dolor adipisci delectus doloremque, officiis reiciendis quod voluptate cupiditate, aliquid maxime cum, doloribus!</p>
</div>
</div><div class="floaters">
<div class="box">
<h3>Some title 20</h3>
<p>Labore animi illo eveniet aliquam est, accusamus saepe obcaecati provident omnis esse repellat atque optio sequi, voluptate nesciunt expedita maxime! Dolorum ipsam corporis laboriosam eveniet aut quas? Temporibus repudiandae, est autem aspernatur optio!</p>
</div>
</div>
</div>
</div>
<script src='lodash.compat.js'></script>
<script>
// usage: log('inside coolFunc',this,arguments);
// http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function(){
log.history = log.history || []; // store logs to an array for reference
log.history.push(arguments);
if(this.console){
console.log( Array.prototype.slice.call(arguments) );
}
};
var addEvent = window.attachEvent||window.addEventListener;
var event = window.attachEvent ? 'onload' : 'load';
window.addEvent(event, function(event) {
//setTimeout( function() {
var _floaters;
var blocks = [], count = 0;
try {
_floaters = [].slice.call(document.querySelectorAll('.floaters'));
}
catch (e) {
var getFloaters = document.querySelectorAll('.floaters');
_floaters = [];
_(getFloaters).forEach(function (f) {
_floaters.push(f);
})
}
log(_floaters);
function getBoundingClientRect(element){
var scrollTop = document.documentElement.scrollTop;
var scrollLeft = document.documentElement.scrollLeft;
if (element.getBoundingClientRect){
if (typeof arguments.callee.offset != "number"){
var temp = document.createElement("div");
temp.style.cssText = "position:absolute;left:0;top:0;";
document.body.appendChild(temp);
arguments.callee.offset = -temp.getBoundingClientRect().top -
scrollTop;
document.body.removeChild(temp);
temp = null;
}
var rect = element.getBoundingClientRect();
var offset = arguments.callee.offset;
return {
left: rect.left + offset,
right: rect.right + offset,
top: rect.top + offset,
bottom: rect.bottom + offset
};
} else {
var actualLeft = getElementLeft(element);
var actualTop = getElementTop(element);
return {
left: actualLeft - scrollLeft,
right: actualLeft + element.offsetWidth - scrollLeft,
top: actualTop - scrollTop,
bottom: actualTop + element.offsetHeight - scrollTop
};
}
}
_floaters.forEach(function (i) {
var _block = getBoundingClientRect(i);
_block['topPos'] = 0;
_block['height'] = _block['bottom'] - _block['top'];
_block['index'] = count;
blocks.push(_block);
count++;
});
var bricks = _.groupBy(blocks, 'top');
window.Bricks = bricks;
var indexes = _.keys(bricks);
var maxCells = _.size(_.max(Bricks, function(b) {return b.length;}));
var container = document.getElementById('container');
var avWidth = container.getBoundingClientRect().width;
var colWidth = Math.floor(_floaters[0].getBoundingClientRect().width);
var maxCols = Math.floor(avWidth / colWidth);
//alert("The container is "+avWidth+" pixels wide and can contain a maximum of "+maxCols+" columns per row");
var matrix = [];
log(blocks);
for(var i = 0, j = indexes.length; i < j; i++) {
(function(i) {
var pSet = bricks[indexes[i - 1]],
thisSet = bricks[indexes[i]],
shortest = _.min(thisSet, 'height'),
topPos = 0;
_(thisSet).forEach( function (b, x) {
var cssString = " position: absolute;";
cssString += " left: "+(colWidth * x)+"px;";
//var mt = b['top'];
if(pSet) {
b['topPos'] = topPos + b['height'];
}
else {
b['topPos'] = b['height'];
log("no pSet: "+x+": "+b['topPos']);
}
cssString += " top: "+topPos+"px;";
_floaters[b['index']].style.cssText += cssString;
});
})(i);
}
container.style.visibility = "visible";
//}, 3000);
// for(var i = 0, j = indexes.length; i < j; i++) {
// (function(i) {
// var topSet = bricks[indexes[i - 1]],
// bottomSet = bricks[indexes[i]],
// shortest = _.min(bottomSet, 'height');
// log(shortest);
// _(topSet).forEach( function (b, x) {
// if(bottomSet[x]['top'] !== b['bottom']) {
// var mt = bottomSet[x]['top'] - b['bottom'];
// log(mt, bottomSet[x]);
// //setTimeout(function () {
// _floaters[bottomSet[x].index].style.marginTop = (mt * -1)+'px';
// //}, 3000)
// // bottomSet[x]['top'] = bottomSet[x]['top'] - mt;
// // bottomSet[x]['bottom'] = bottomSet[x]['bottom'] - mt;
// }
// });
// })(i);
// }
});
</script>
</body>
</html>