瀑布流布局插件Macy.Js
完整代码
下面的html部分使用的是cdn链接的,可以直接预览看效果,避免链接失效在上面贴了
css
和js
部分源代码
css部分
css
/*! Copyright (c) 2015 Big Bite Creative | bigbitecreative.com | @bigbitecreative */
@import url(http://fonts.googleapis.com/css?family=Source+Sans+Pro:400,600);
/**
* 1. Set default font family to sans-serif.
* 2. Prevent iOS text size adjust after orientation change, without disabling
* user zoom.
*/
html {
font-family: sans-serif;
/* 1 */
-ms-text-size-adjust: 100%;
/* 2 */
-webkit-text-size-adjust: 100%;
/* 2 */ }
/**
* Remove default margin.
*/
body {
margin: 0; }
/* HTML5 display definitions
========================================================================== */
/**
* Correct `block` display not defined for any HTML5 element in IE 8/9.
* Correct `block` display not defined for `details` or `summary` in IE 10/11 and Firefox.
* Correct `block` display not defined for `main` in IE 11.
*/
article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
main,
nav,
section,
summary {
display: block; }
/**
* 1. Correct `inline-block` display not defined in IE 8/9.
* 2. Normalize vertical alignment of `progress` in Chrome, Firefox, and Opera.
*/
audio,
canvas,
progress,
video {
display: inline-block;
/* 1 */
vertical-align: baseline;
/* 2 */ }
/**
* Prevent modern browsers from displaying `audio` without controls.
* Remove excess height in iOS 5 devices.
*/
audio:not([controls]) {
display: none;
height: 0; }
/**
* Address `[hidden]` styling not present in IE 8/9/10.
* Hide the `template` element in IE 8/9/11, Safari, and Firefox < 22.
*/
[hidden],
template {
display: none; }
/* Links
========================================================================== */
/**
* Remove the gray background color from active links in IE 10.
*/
a {
background: transparent; }
/**
* Improve readability when focused and also mouse hovered in all browsers.
*/
a:active,
a:hover {
outline: 0; }
/* Text-level semantics
========================================================================== */
/**
* Address styling not present in IE 8/9/10/11, Safari, and Chrome.
*/
abbr[title] {
border-bottom: 1px dotted; }
/**
* Address style set to `bolder` in Firefox 4+, Safari, and Chrome.
*/
b,
strong {
font-weight: bold; }
/**
* Address styling not present in Safari and Chrome.
*/
dfn {
font-style: italic; }
/**
* Address variable `h1` font-size and margin within `section` and `article`
* contexts in Firefox 4+, Safari, and Chrome.
*/
h1 {
font-size: 2em;
margin: 0.67em 0; }
/**
* Address styling not present in IE 8/9.
*/
mark {
background: #ff0;
color: #000; }
/**
* Address inconsistent and variable font size in all browsers.
*/
small {
font-size: 80%; }
/**
* Prevent `sub` and `sup` affecting `line-height` in all browsers.
*/
sub,
sup {
font-size: 75%;
line-height: 0;
position: relative;
vertical-align: baseline; }
sup {
top: -0.5em; }
sub {
bottom: -0.25em; }
/* Embedded content
========================================================================== */
/**
* Remove border when inside `a` element in IE 8/9/10.
*/
img {
border: 0; }
/**
* Correct overflow not hidden in IE 9/10/11.
*/
svg:not(:root) {
overflow: hidden; }
/* Grouping content
========================================================================== */
/**
* Address margin not present in IE 8/9 and Safari.
*/
figure {
margin: 1em 40px; }
/**
* Address differences between Firefox and other browsers.
*/
hr {
box-sizing: content-box;
height: 0; }
/**
* Contain overflow in all browsers.
*/
pre {
overflow: auto; }
/**
* Address odd `em`-unit font size rendering in all browsers.
*/
code,
kbd,
pre,
samp {
font-family: monospace, monospace;
font-size: 1em; }
/* Forms
========================================================================== */
/**
* Known limitation: by default, Chrome and Safari on OS X allow very limited
* styling of `select`, unless a `border` property is set.
*/
/**
* 1. Correct color not being inherited.
* Known issue: affects color of disabled elements.
* 2. Correct font properties not being inherited.
* 3. Address margins set differently in Firefox 4+, Safari, and Chrome.
*/
button,
input,
optgroup,
select,
textarea {
color: inherit;
/* 1 */
font: inherit;
/* 2 */
margin: 0;
/* 3 */ }
/**
* Address `overflow` set to `hidden` in IE 8/9/10/11.
*/
button {
overflow: visible; }
/**
* Address inconsistent `text-transform` inheritance for `button` and `select`.
* All other form control elements do not inherit `text-transform` values.
* Correct `button` style inheritance in Firefox, IE 8/9/10/11, and Opera.
* Correct `select` style inheritance in Firefox.
*/
button,
select {
text-transform: none; }
/**
* 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio`
* and `video` controls.
* 2. Correct inability to style clickable `input` types in iOS.
* 3. Improve usability and consistency of cursor style between image-type
* `input` and others.
*/
button,
html input[type="button"], input[type="reset"],
input[type="submit"] {
-webkit-appearance: button;
/* 2 */
cursor: pointer;
/* 3 */ }
/**
* Re-set default cursor for disabled elements.
*/
button[disabled],
html input[disabled] {
cursor: default; }
/**
* Remove inner padding and border in Firefox 4+.
*/
button::-moz-focus-inner,
input::-moz-focus-inner {
border: 0;
padding: 0; }
/**
* Address Firefox 4+ setting `line-height` on `input` using `!important` in
* the UA stylesheet.
*/
input {
line-height: normal; }
/**
* It's recommended that you don't attempt to style these elements.
* Firefox's implementation doesn't respect box-sizing, padding, or width.
*
* 1. Address box sizing set to `content-box` in IE 8/9/10.
* 2. Remove excess padding in IE 8/9/10.
*/
input[type="checkbox"],
input[type="radio"] {
box-sizing: border-box;
/* 1 */
padding: 0;
/* 2 */ }
/**
* Fix the cursor style for Chrome's increment/decrement buttons. For certain
* `font-size` values of the `input`, it causes the cursor style of the
* decrement button to change from `default` to `text`.
*/
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
height: auto; }
/**
* 1. Address `appearance` set to `searchfield` in Safari and Chrome.
* 2. Address `box-sizing` set to `border-box` in Safari and Chrome
* (include `-moz` to future-proof).
*/
input[type="search"] {
-webkit-appearance: textfield;
/* 1 */
/* 2 */
box-sizing: content-box; }
/**
* Remove inner padding and search cancel button in Safari and Chrome on OS X.
* Safari (but not Chrome) clips the cancel button when the search input has
* padding (and `textfield` appearance).
*/
input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-decoration {
-webkit-appearance: none; }
/**
* Define consistent border, margin, and padding.
*/
fieldset {
border: 1px solid #c0c0c0;
margin: 0 2px;
padding: 0.35em 0.625em 0.75em; }
/**
* 1. Correct `color` not being inherited in IE 8/9/10/11.
* 2. Remove padding so people aren't caught out if they zero out fieldsets.
*/
legend {
border: 0;
/* 1 */
padding: 0;
/* 2 */ }
/**
* Remove default vertical scrollbar in IE 8/9/10/11.
*/
textarea {
overflow: auto; }
/**
* Don't inherit the `font-weight` (applied by a rule above).
* NOTE: the default cannot safely be changed in Chrome and Safari on OS X.
*/
optgroup {
font-weight: bold; }
/* Tables
========================================================================== */
/**
* Remove most spacing between table cells.
*/
table {
border-collapse: collapse;
border-spacing: 0; }
td,
th {
padding: 0; }
/**
* As well as using normalize.css, it is often advantageous to
* remove all margins from certain elements.
*/
body,
h1, h2, h3, h4, h5, h6,
p, blockquote, pre,
dl, dd, ol, ul,
form, fieldset, legend,
table, th, td, caption,
hr {
margin: 0;
padding: 0; }
/**
* Where `margin-bottom` is concerned, this value will be the same as the
* base line-height. This allows us to keep a consistent vertical rhythm.
*/
h1, h2, h3, h4, h5, h6, hgroup,
ul, ol, dl,
blockquote, p, address,
table,
fieldset, figure,
pre {
margin-bottom: 24px; }
/**
* Where `margin-left` is concerned we want to try and indent certain elements
* by a consistent amount. Define that amount once,here.
*/
ul, ol, dd {
margin-left: 48px; }
* {
box-sizing: border-box;
}
body {
color: #4d4d4d;
font-family: 'Source Sans Pro', sans-serif;
}
a:not(.btn),
a:visited:not(.btn) {
color: #54b9cb;
text-decoration: none;
}
a:not(.btn):hover,
a:not(.btn):active,
a:not(.btn):focus {
color: #4CA8B9;
}
.container {
max-width: 100%;
width: 1128px;
padding: 0 24px;
margin: 0 auto;
}
.hero {
text-align: center;
padding: 120px 0 70px;
border-bottom: 1px solid #e5e5e5;
}
.hero__title {
font-size: 20px;
font-weight: 300;
width: 55%;
line-height: 1.6;
margin: 0 auto 40px;
}
.logo { margin-bottom: 50px; }
img { max-width: 100%; }
.section { padding: 50px 0; }
.section:not(:last-child) { border-bottom: 1px solid #e5e5e5; }
#macy-container::before { content: ""; display: table; clear: both;}
#macy-container { margin-top: 22px; }
#macy-container::after { content: ""; display: table; clear: both;}
.demo {
margin-bottom: 24px;
border-radius: 4px;
overflow: hidden;
border: 1px solid #eee;
}
.demo-image {
width: 100%;
display: block;
height: auto;
}
.feature-list {
margin-bottom: 0;
margin-left: 0;
width: 100%;
list-style: none;
}
.feature-list li {
display: inline-block;
width: 25%;
text-align: center;
}
.feature-list li::before {
color: inherit;
content: "•";
color: #54b9cb;
margin-right: 7px;
}
.btn {
background-color: #54b9cb;
line-height: 53px;
padding: 0 18px 0 0;
display: inline-block;
text-decoration: none;
color: #fff;
border-radius: 4px;
transition: all .25s ease-in-out;
font-size: 18px;
}
.btn:hover {
background-color: #4CA8B9;
}
.btn.has-icon::before {
margin-right: 18px;
padding: 0 18px;
border-right: 1px solid #4daabb;
line-height: 53px;
}
footer {
padding: 80px 0;
text-align: center;
}
@media screen and (max-width: 800px) {
.hero__title {
width: 80%;
}
.feature-list li {
width: 50%;
line-height: 2;
}
}
@media screen and (max-width: 600px) {
.hero {
padding: 60px 0 40px;
}
.hero__title {
width: 100%;
}
.feature-list li {
width: 100%;
line-height: 2;
}
.section {
padding: 25px 0;
}
.footer {
padding: 0 0 40px;
}
}
@media screen and (max-width: 400px) {
.btn.has-icon {
padding: 18px;
line-height: 1.2;
}
.btn.has-icon::before {
display: none;
}
}
js部分
js
!(function (t, n) {
"object" == typeof exports && "undefined" != typeof module
? (module.exports = n())
: "function" == typeof define && define.amd
? define(n)
: (t.Macy = n());
})(this, function () {
"use strict";
function t(t, n) {
var e = void 0;
return function () {
e && clearTimeout(e), (e = setTimeout(t, n));
};
}
function n(t, n) {
for (var e = t.length, r = e, o = []; e--; ) o.push(n(t[r - e - 1]));
return o;
}
function e(t, n) {
var e = arguments.length > 2 && void 0 !== arguments[2] && arguments[2];
if (window.Promise) return A(t, n, e);
t.recalculate(!0, !0);
}
function r(t) {
for (
var n = t.options,
e = t.responsiveOptions,
r = t.keys,
o = t.docWidth,
i = void 0,
s = 0;
s < r.length;
s++
) {
var a = parseInt(r[s], 10);
o >= a && ((i = n.breakAt[a]), O(i, e));
}
return e;
}
function o(t) {
for (
var n = t.options,
e = t.responsiveOptions,
r = t.keys,
o = t.docWidth,
i = void 0,
s = r.length - 1;
s >= 0;
s--
) {
var a = parseInt(r[s], 10);
o <= a && ((i = n.breakAt[a]), O(i, e));
}
return e;
}
function i(t) {
var n = t.useContainerForBreakpoints
? t.container.clientWidth
: window.innerWidth,
e = { columns: t.columns };
b(t.margin)
? (e.margin = { x: t.margin.x, y: t.margin.y })
: (e.margin = { x: t.margin, y: t.margin });
var i = Object.keys(t.breakAt);
return t.mobileFirst
? r({ options: t, responsiveOptions: e, keys: i, docWidth: n })
: o({ options: t, responsiveOptions: e, keys: i, docWidth: n });
}
function s(t) {
return i(t).columns;
}
function a(t) {
return i(t).margin;
}
function c(t) {
var n = !(arguments.length > 1 && void 0 !== arguments[1]) || arguments[1],
e = s(t),
r = a(t).x,
o = 100 / e;
if (!n) return o;
if (1 === e) return "100%";
var i = "px";
if ("string" == typeof r) {
var c = parseFloat(r);
(i = r.replace(c, "")), (r = c);
}
return (
(r = ((e - 1) * r) / e),
"%" === i ? o - r + "%" : "calc(" + o + "% - " + r + i + ")"
);
}
function u(t, n) {
var e = s(t.options),
r = 0,
o = void 0,
i = void 0;
if (1 === ++n) return 0;
i = a(t.options).x;
var u = "px";
if ("string" == typeof i) {
var l = parseFloat(i, 10);
(u = i.replace(l, "")), (i = l);
}
return (
(o = (i - ((e - 1) * i) / e) * (n - 1)),
(r += c(t.options, !1) * (n - 1)),
"%" === u ? r + o + "%" : "calc(" + r + "% + " + o + u + ")"
);
}
function l(t) {
var n = 0,
e = t.container,
r = t.rows;
v(r, function (t) {
n = t > n ? t : n;
}),
(e.style.height = n + "px");
}
function p(t, n) {
var e = arguments.length > 2 && void 0 !== arguments[2] && arguments[2],
r = !(arguments.length > 3 && void 0 !== arguments[3]) || arguments[3],
o = s(t.options),
i = a(t.options).y;
M(t, o, e),
v(n, function (n) {
var e = 0,
o = parseInt(n.offsetHeight, 10);
isNaN(o) ||
(t.rows.forEach(function (n, r) {
n < t.rows[e] && (e = r);
}),
(n.style.position = "absolute"),
(n.style.top = t.rows[e] + "px"),
(n.style.left = "" + t.cols[e]),
(t.rows[e] += isNaN(o) ? 0 : o + i),
r && (n.dataset.macyComplete = 1));
}),
r && (t.tmpRows = null),
l(t);
}
function f(t, n) {
var e = arguments.length > 2 && void 0 !== arguments[2] && arguments[2],
r = !(arguments.length > 3 && void 0 !== arguments[3]) || arguments[3],
o = s(t.options),
i = a(t.options).y;
M(t, o, e),
v(n, function (n) {
t.lastcol === o && (t.lastcol = 0);
var e = C(n, "height");
(e = parseInt(n.offsetHeight, 10)),
isNaN(e) ||
((n.style.position = "absolute"),
(n.style.top = t.rows[t.lastcol] + "px"),
(n.style.left = "" + t.cols[t.lastcol]),
(t.rows[t.lastcol] += isNaN(e) ? 0 : e + i),
(t.lastcol += 1),
r && (n.dataset.macyComplete = 1));
}),
r && (t.tmpRows = null),
l(t);
}
var h = function t(n, e) {
if (!(this instanceof t)) return new t(n, e);
if (n && n.nodeName) return n;
if (((n = n.replace(/^\s*/, "").replace(/\s*$/, "")), e))
return this.byCss(n, e);
for (var r in this.selectors)
if (((e = r.split("/")), new RegExp(e[1], e[2]).test(n)))
return this.selectors[r](n);
return this.byCss(n);
};
(h.prototype.byCss = function (t, n) {
return (n || document).querySelectorAll(t);
}),
(h.prototype.selectors = {}),
(h.prototype.selectors[/^\.[\w\-]+$/] = function (t) {
return document.getElementsByClassName(t.substring(1));
}),
(h.prototype.selectors[/^\w+$/] = function (t) {
return document.getElementsByTagName(t);
}),
(h.prototype.selectors[/^\#[\w\-]+$/] = function (t) {
return document.getElementById(t.substring(1));
});
var v = function (t, n) {
for (var e = t.length, r = e; e--; ) n(t[r - e - 1]);
},
m = function () {
var t = arguments.length > 0 && void 0 !== arguments[0] && arguments[0];
(this.running = !1), (this.events = []), this.add(t);
};
(m.prototype.run = function () {
if (!this.running && this.events.length > 0) {
var t = this.events.shift();
(this.running = !0), t(), (this.running = !1), this.run();
}
}),
(m.prototype.add = function () {
var t = this,
n = arguments.length > 0 && void 0 !== arguments[0] && arguments[0];
return (
!!n &&
(Array.isArray(n)
? v(n, function (n) {
return t.add(n);
})
: (this.events.push(n), void this.run()))
);
}),
(m.prototype.clear = function () {
this.events = [];
});
var d = function (t) {
var n =
arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
return (this.instance = t), (this.data = n), this;
},
y = function () {
var t = arguments.length > 0 && void 0 !== arguments[0] && arguments[0];
(this.events = {}), (this.instance = t);
};
(y.prototype.on = function () {
var t = arguments.length > 0 && void 0 !== arguments[0] && arguments[0],
n = arguments.length > 1 && void 0 !== arguments[1] && arguments[1];
return (
!(!t || !n) &&
(Array.isArray(this.events[t]) || (this.events[t] = []),
this.events[t].push(n))
);
}),
(y.prototype.emit = function () {
var t = arguments.length > 0 && void 0 !== arguments[0] && arguments[0],
n = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
if (!t || !Array.isArray(this.events[t])) return !1;
var e = new d(this.instance, n);
v(this.events[t], function (t) {
return t(e);
});
});
var g = function (t) {
return (
!("naturalHeight" in t && t.naturalHeight + t.naturalWidth === 0) ||
t.width + t.height !== 0
);
},
E = function (t, n) {
var e = arguments.length > 2 && void 0 !== arguments[2] && arguments[2];
return new Promise(function (t, e) {
if (n.complete) return g(n) ? t(n) : e(n);
n.addEventListener("load", function () {
return g(n) ? t(n) : e(n);
}),
n.addEventListener("error", function () {
return e(n);
});
})
.then(function (n) {
e && t.emit(t.constants.EVENT_IMAGE_LOAD, { img: n });
})
.catch(function (n) {
return t.emit(t.constants.EVENT_IMAGE_ERROR, { img: n });
});
},
w = function (t, e) {
var r = arguments.length > 2 && void 0 !== arguments[2] && arguments[2];
return n(e, function (n) {
return E(t, n, r);
});
},
A = function (t, n) {
var e = arguments.length > 2 && void 0 !== arguments[2] && arguments[2];
return Promise.all(w(t, n, e)).then(function () {
t.emit(t.constants.EVENT_IMAGE_COMPLETE);
});
},
I = function (n) {
return t(function () {
n.emit(n.constants.EVENT_RESIZE),
n.queue.add(function () {
return n.recalculate(!0, !0);
});
}, 100);
},
N = function (t) {
if (
((t.container = h(t.options.container)),
t.container instanceof h || !t.container)
)
return !!t.options.debug && console.error("Error: Container not found");
t.container.length && (t.container = t.container[0]),
(t.options.container = t.container),
(t.container.style.position = "relative");
},
T = function (t) {
(t.queue = new m()),
(t.events = new y(t)),
(t.rows = []),
(t.resizer = I(t));
},
L = function (t) {
var n = h("img", t.container);
window.addEventListener("resize", t.resizer),
t.on(t.constants.EVENT_IMAGE_LOAD, function () {
return t.recalculate(!1, !1);
}),
t.on(t.constants.EVENT_IMAGE_COMPLETE, function () {
return t.recalculate(!0, !0);
}),
t.options.useOwnImageLoader || e(t, n, !t.options.waitForImages),
t.emit(t.constants.EVENT_INITIALIZED);
},
_ = function (t) {
N(t), T(t), L(t);
},
b = function (t) {
return (
t === Object(t) &&
"[object Array]" !== Object.prototype.toString.call(t)
);
},
O = function (t, n) {
b(t) || (n.columns = t),
b(t) && t.columns && (n.columns = t.columns),
b(t) &&
t.margin &&
!b(t.margin) &&
(n.margin = { x: t.margin, y: t.margin }),
b(t) &&
t.margin &&
b(t.margin) &&
t.margin.x &&
(n.margin.x = t.margin.x),
b(t) &&
t.margin &&
b(t.margin) &&
t.margin.y &&
(n.margin.y = t.margin.y);
},
C = function (t, n) {
return window.getComputedStyle(t, null).getPropertyValue(n);
},
M = function (t, n) {
var e = arguments.length > 2 && void 0 !== arguments[2] && arguments[2];
if ((t.lastcol || (t.lastcol = 0), t.rows.length < 1 && (e = !0), e)) {
(t.rows = []), (t.cols = []), (t.lastcol = 0);
for (var r = n - 1; r >= 0; r--) (t.rows[r] = 0), (t.cols[r] = u(t, r));
} else if (t.tmpRows) {
t.rows = [];
for (var r = n - 1; r >= 0; r--) t.rows[r] = t.tmpRows[r];
} else {
t.tmpRows = [];
for (var r = n - 1; r >= 0; r--) t.tmpRows[r] = t.rows[r];
}
},
V = function (t) {
var n = arguments.length > 1 && void 0 !== arguments[1] && arguments[1],
e = !(arguments.length > 2 && void 0 !== arguments[2]) || arguments[2],
r = n
? t.container.children
: h(':scope > *:not([data-macy-complete="1"])', t.container);
r = Array.from(r).filter(function (t) {
return null !== t.offsetParent;
});
var o = c(t.options);
return (
v(r, function (t) {
n && (t.dataset.macyComplete = 0), (t.style.width = o);
}),
t.options.trueOrder
? (f(t, r, n, e), t.emit(t.constants.EVENT_RECALCULATED))
: (p(t, r, n, e), t.emit(t.constants.EVENT_RECALCULATED))
);
},
R = function () {
return !!window.Promise;
},
x =
Object.assign ||
function (t) {
for (var n = 1; n < arguments.length; n++) {
var e = arguments[n];
for (var r in e)
Object.prototype.hasOwnProperty.call(e, r) && (t[r] = e[r]);
}
return t;
};
Array.from ||
(Array.from = function (t) {
for (var n = 0, e = []; n < t.length; ) e.push(t[n++]);
return e;
});
var k = {
columns: 4,
margin: 2,
trueOrder: !1,
waitForImages: !1,
useImageLoader: !0,
breakAt: {},
useOwnImageLoader: !1,
onInit: !1,
cancelLegacy: !1,
useContainerForBreakpoints: !1,
};
!(function () {
try {
document.createElement("a").querySelector(":scope *");
} catch (t) {
!(function () {
function t(t) {
return function (e) {
if (e && n.test(e)) {
var r = this.getAttribute("id");
r || (this.id = "q" + Math.floor(9e6 * Math.random()) + 1e6),
(arguments[0] = e.replace(n, "#" + this.id));
var o = t.apply(this, arguments);
return (
null === r ? this.removeAttribute("id") : r || (this.id = r), o
);
}
return t.apply(this, arguments);
};
}
var n = /:scope\b/gi,
e = t(Element.prototype.querySelector);
Element.prototype.querySelector = function (t) {
return e.apply(this, arguments);
};
var r = t(Element.prototype.querySelectorAll);
Element.prototype.querySelectorAll = function (t) {
return r.apply(this, arguments);
};
})();
}
})();
var q = function t() {
var n = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : k;
if (!(this instanceof t)) return new t(n);
(this.options = {}),
x(this.options, k, n),
(this.options.cancelLegacy && !R()) || _(this);
};
return (
(q.init = function (t) {
return (
console.warn(
"Depreciated: Macy.init will be removed in v3.0.0 opt to use Macy directly like so Macy({ /*options here*/ }) "
),
new q(t)
);
}),
(q.prototype.recalculateOnImageLoad = function () {
var t = arguments.length > 0 && void 0 !== arguments[0] && arguments[0];
return e(this, h("img", this.container), !t);
}),
(q.prototype.runOnImageLoad = function (t) {
var n = arguments.length > 1 && void 0 !== arguments[1] && arguments[1],
r = h("img", this.container);
return (
this.on(this.constants.EVENT_IMAGE_COMPLETE, t),
n && this.on(this.constants.EVENT_IMAGE_LOAD, t),
e(this, r, n)
);
}),
(q.prototype.recalculate = function () {
var t = this,
n = arguments.length > 0 && void 0 !== arguments[0] && arguments[0],
e = !(arguments.length > 1 && void 0 !== arguments[1]) || arguments[1];
return (
e && this.queue.clear(),
this.queue.add(function () {
return V(t, n, e);
})
);
}),
(q.prototype.remove = function () {
window.removeEventListener("resize", this.resizer),
v(this.container.children, function (t) {
t.removeAttribute("data-macy-complete"), t.removeAttribute("style");
}),
this.container.removeAttribute("style");
}),
(q.prototype.reInit = function () {
this.recalculate(!0, !0),
this.emit(this.constants.EVENT_INITIALIZED),
window.addEventListener("resize", this.resizer),
(this.container.style.position = "relative");
}),
(q.prototype.on = function (t, n) {
this.events.on(t, n);
}),
(q.prototype.emit = function (t, n) {
this.events.emit(t, n);
}),
(q.constants = {
EVENT_INITIALIZED: "macy.initialized",
EVENT_RECALCULATED: "macy.recalculated",
EVENT_IMAGE_LOAD: "macy.image.load",
EVENT_IMAGE_ERROR: "macy.image.error",
EVENT_IMAGE_COMPLETE: "macy.images.complete",
EVENT_RESIZE: "macy.resize",
}),
(q.prototype.constants = q.constants),
q
);
});
html部分
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/jinweizhe/cdn/macy/macy.css">
<!-- <link rel="stylesheet" href="./macy.css"> -->
</head>
<body>
<div id="macy-container">
<!-- 第一行 -->
<div>
<img style="width: 80px;" src="https://profile-avatar.csdnimg.cn/eefff198cd5e41ccbaea441c5f866c5f_weixin_68658847.jpg!1" alt="">
</div>
<div>
<img style="width: 20px;" src="https://thirdwx.qlogo.cn/mmopen/LiaXXhXicIsISKsbYyos3mwHUfW0JzGfgbSWiahBxU5Y1GMFYxdAEogSCvstM39kkP5AYWF0C9dhU6ibMhPFOQMfm0RfPMqUqMHM/132" alt="">
</div>
<div>
<img src="https://take-saas.oss-cn-hangzhou.aliyuncs.com/wechat_applets/coach/bgcimg/bgc-13.png" alt="">
</div>
<div>
<img src="https://take-saas.oss-cn-hangzhou.aliyuncs.com/wechat_applets/coach/bgcimg/bgc-13.png" alt="">
</div>
<div>
<img src="https://take-saas.oss-cn-hangzhou.aliyuncs.com/wechat_applets/coach/bgcimg/bgc-13.png" alt="">
</div>
<!-- 第二行 -->
<div>
<img src="https://take-saas.oss-cn-hangzhou.aliyuncs.com/wechat_applets/coach/bgcimg/bgc-13.png" alt="">
</div>
<div>
<img src="https://take-saas.oss-cn-hangzhou.aliyuncs.com/wechat_applets/coach/bgcimg/bgc-13.png" alt="">
</div>
</div>
</body>
<script src="https://cdn.jsdelivr.net/gh/jinweizhe/cdn/macy/macy.js"></script>
<!-- <script src="./macy.js"></script> -->
<script>
window.onload=function(){
var masonry = new Macy({
container: '#macy-container', // 图像列表容器id
trueOrder: false,
waitForImages: false,
useOwnImageLoader: false,
debug: true,
//设计间距
margin: {
x: 10,
y: 10
},
//设置列数
columns: 4,
//定义不同分辨率(1200,940,520,400这些是分辨率)
breakAt: {
1200: {
columns: 5,
margin: {
x: 23,
y: 4
}
},
940: {
margin: {
y: 23
}
},
520: {
columns: 3,
margin: 3,
},
400: {
columns: 2
}
}
});
}
</script>
</html>