waterflow.js
Version:
[Demo](http://alex-xueyao.gitee.io/v3pro/#/laolai)
2 lines (1 loc) • 3.31 kB
JavaScript
import e from"@babel/runtime/helpers/toConsumableArray";import"core-js/modules/es.array.from.js";import"core-js/modules/es.string.iterator.js";import"core-js/modules/es.array.includes.js";import"core-js/modules/web.timers.js";import"core-js/modules/es.array.concat.js";import"core-js/modules/es.array.slice.js";import"core-js/modules/es.object.to-string.js";import"core-js/modules/es.function.name.js";import"core-js/modules/es.symbol.js";import"core-js/modules/es.symbol.description.js";import"core-js/modules/es.symbol.iterator.js";import"core-js/modules/es.array.iterator.js";import"core-js/modules/web.dom-collections.iterator.js";import"core-js/modules/es.array.is-array.js";function r(e,r){var o="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!o){if(Array.isArray(e)||(o=function(e,r){if(!e)return;if("string"==typeof e)return t(e,r);var o=Object.prototype.toString.call(e).slice(8,-1);"Object"===o&&e.constructor&&(o=e.constructor.name);if("Map"===o||"Set"===o)return Array.from(e);if("Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o))return t(e,r)}(e))||r&&e&&"number"==typeof e.length){o&&(e=o);var n=0,s=function(){};return{s:s,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,l=!1;return{s:function(){o=o.call(e)},n:function(){var e=o.next();return a=e.done,e},e:function(e){l=!0,i=e},f:function(){try{a||null==o.return||o.return()}finally{if(l)throw i}}}}function t(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,o=new Array(r);t<r;t++)o[t]=e[t];return o}var o=["fixed","relative","absolute"];function n(t,n){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,a=arguments.length>3&&void 0!==arguments[3]&&arguments[3],l=arguments.length>4&&void 0!==arguments[4]?arguments[4]:300;if(t&&n){var c=Array.from(t.children),m=t.clientWidth,u=getComputedStyle(t);o.includes(u.position)||t.style.setProperty("position","relative");for(var f=Math.floor((m+i)/(n+i)),p=0,d=c;p<d.length;p++){var y=d[p],v=[].concat(e(Array.from(y.querySelectorAll("img"))),e(Array.from(y.querySelectorAll("video"))));if(v.length){var j,h=r(v);try{for(h.s();!(j=h.n()).done;){var g=j.value;if("img"===g.nodeName.toLowerCase()){var b=new Image;b.onload=function(){x()},b.src=g.src}"video"===g.nodeName.toLowerCase()&&(g.onloadedmetadata=function(){x()})}}catch(e){h.e(e)}finally{h.f()}}else x()}}function x(){setTimeout((function(){s(t,c,n,i,f,a)}),l)}}function s(e,r,t,o,n,s){for(var l=[],c=0;c<r.length;c++){var m=r[c],u=m.clientHeight;if(c<n){var f={left:0===c?0:t*c+o*c,top:0,height:u};l.push(f),i(m,f),l[c].top+=u+o;var p=l[a(l).maxIndex].top;e.style.setProperty("min-height","".concat(p,"px"))}else{var d=a(l).minIndex;s&&(d=c%n),i(m,l[d]),l[d].top+=u+o;var y=l[a(l).maxIndex].top;e.style.setProperty("min-height","".concat(y,"px"))}}}function i(e,r){var t=r.top,o=r.left;e.style.setProperty("position","absolute"),e.style.setProperty("left","".concat(o,"px")),e.style.setProperty("top","".concat(t,"px"))}function a(e){for(var r=0,t=0,o=0;o<e.length;o++)e[r].top>e[o].top&&(r=o),e[t].top<e[o].top&&(t=o);return{minIndex:r,maxIndex:t}}export{n as default};