Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions 18 flex-images.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Copyright (c) 2014 Simon Steinberger / Pixabay
GitHub: https://github.com/Pixabay/JavaScript-flexImages
License: http://www.opensource.org/licenses/mit-license.php
*/
*/

var flexImages = (function(){
// "use strict";
Expand All @@ -29,7 +29,9 @@ var flexImages = (function(){
row_width += items[i][2] + o.margin;
if (row_width >= max_w) {
var margins_in_row = row.length * o.margin;
ratio = (max_w-margins_in_row) / (row_width-margins_in_row), row_h = Math.ceil(o.rowHeight*ratio), exact_w = 0, new_w;
var ratio = (max_w-margins_in_row) / (row_width-margins_in_row);
var row_h = Math.ceil(o.rowHeight*ratio);
var exact_w = 0, new_w;
for (x=0; x<row.length; x++) {
new_w = Math.ceil(row[x][2]*ratio);
exact_w += new_w + o.margin;
Expand Down Expand Up @@ -57,14 +59,19 @@ var flexImages = (function(){

for (var i=0;i<grids.length;i++) {
var grid = grids[i], containers = grid.querySelectorAll(o.container), items = [], t = new Date().getTime();
if (options['rowHeight'] == 'fluid'){
grid.clientWidth > 900 ? o['rowHeight'] = Math.floor(grid.clientWidth / 5) : o['rowHeight'] = 180;
}
if (!containers.length) continue;
var s = window.getComputedStyle ? getComputedStyle(containers[0], null) : containers[0].currentStyle;
o.margin = (parseInt(s.marginLeft) || 0) + (parseInt(s.marginRight) || 0) + (Math.round(parseFloat(s.borderLeftWidth)) || 0) + (Math.round(parseFloat(s.borderRightWidth)) || 0);
for (var j=0;j<containers.length;j++) {
var c = containers[j],
w = parseInt(c.getAttribute('data-w')),
norm_w = w*(o.rowHeight/parseInt(c.getAttribute('data-h'))), // normalized width
obj = c.querySelector(o.object);
w = parseInt(c.getAttribute('data-w')),
obj = c.querySelector(o.object),
objWidth = obj.width,
objHeight = obj.height,
norm_w = objWidth*(o.rowHeight/objHeight);// normalized width
items.push([c, w, norm_w, obj, obj.getAttribute('data-src')]);
}
makeGrid(grid, items, o);
Expand All @@ -90,3 +97,4 @@ var flexImages = (function(){
else
window.flexImages = flexImages;
})();

Morty Proxy This is a proxified and sanitized view of the page, visit original site.