(function( $ ) { $.fn.mozaika= function() { }; })(jQuery);
(function( $ ) { $.fn.mozaika= function() { var set = $.extend( { 'n': 4, 'margin': 4, 'padding' : 30, 'item' : 'item', 'citem2' : 'item-w2', 'citem3' : 'item-w3', 'itembot' : 0 }, options); }; })(jQuery);
var cols = new Array() // for(i = 0; i < set.n; i++) cols[i] = 0;
var width = this.width(); //
var one = (width - set.margin * (set.n - 1))/set.n; // var left = 0; //
(function( $ ) { $.fn.mozaika= function(options) { var set = $.extend( { 'n': 4, 'margin': 4, 'padding' : 30, 'item' : 'item', 'citem2' : 'item-w2', 'citem3' : 'item-w3', 'itembot' : 0 }, options); var cols = new Array() // for(i = 0; i < set.n; i++) cols[i] = 0; var width = this.width(); // var one = (width - set.margin * (set.n - 1))/set.n; // var left = 0; // var moz = this.children('.'+set.item); // i = 0; $(moz).each(function( k, v ) { if($(v).hasClass(set.citem2)){ w = one*2+set.margin; q=2; }else if($(v).hasClass(set.citem3)){ w = one*3+set.margin*2; q=3; }else{ w = one; q = 1; } if(i+q>set.n){ i = 0; } var mx = cols[i]; var mn = i; for(e = i; e <i+q; e++) if(cols[e] > mx){ mx = cols[e]; mn = e; } $(v).css({'position':'absolute', 'width' : w+'px'}); $(v).css({'left' : left+'px', 'top':mx, 'padding-bottom':set.itembot}); $(v).animate({opacity:1},1000); hg = cols[i]; for(e = i; e < i+q; e++){ cols[e] = hg + $(v).height() + set.margin + set.itembot; //console.log('n ' + i + ' q ' + q + ' cols[' + e + '] ' + cols[e]); } left = left + set.margin + w; i = i+q; if(i>=set.n){ i=0; left = 0; } }); mx = cols[0]; for(e = 0; e <set.n; e++) if(cols[e] > mx){ mx = cols[e]; } if(this.height()<(mx+set.padding*2)) this.height(mx+set.padding*2); }; })(jQuery);
$(document).ready(function(e) { $(".catalog").moZaika({ 'n': 4, 'margin': 2, 'item' : 'cat-item', 'citem2' : 'cat-w2', 'citem3' : 'cat-w3', 'itembot' : 20, 'padding' : 0 }); });
Source: https://habr.com/ru/post/274683/
All Articles