hongkhanh / gridify Goto Github PK
View Code? Open in Web Editor NEWA lightweight script for creating a Pinterest-like grid using JQuery, pure javascript or YUI with image loaded
Home Page: http://hongkhanh.github.io/gridify
License: MIT License
A lightweight script for creating a Pinterest-like grid using JQuery, pure javascript or YUI with image loaded
Home Page: http://hongkhanh.github.io/gridify
License: MIT License
Having this issue - the img
s only get layed out after I either zoom in or zoom out on the page. This doesn't happen on any of the example pages.
This is my code:
$(document).ready(function(){
var albumId = "xxxxxxxxxxxxx";
$.ajax({
dataType:"json",
url:'http://graph.facebook.com/' + albumId + '?fields=photos.fields%28images,source,picture,link,name%29,photos.limit%2840%29&_=1425840156371',
success:function(incomming){
var photos = incomming.photos.data;
for (var key in photos){
$("#photos").append("<img src='" + photos[key].source + "' class='image'>");
}
},
error:function(err){
console.log("Error collecting photos: " + JSON.stringify(err, null, 2));
}
});
});
$(window).load(function() {
var options = {
items:3,
srcNode: 'img',
margin: '20px',
width: '250px',
resizable: true,
transition: 'all 0.5s ease'
}
$('.grid').gridify(options);
});
My .grid
element starts out as an empty div
.
Hi,
I hade a problem with the items container height. As long as items use absolute positing, so the container does not extend while items render. so i come with these lines of code to calculate height on window resizing:
var child_max = $item.position().top+$item.outerHeight();
if(child_max>parent_height) parent_height=child_max;
that should placed inside 'rebder' function.
It's complete changes tha i've made to this method:
render = function()
{
$this.css('position', 'relative');
var items = $this.find(options.srcNode),
transition = (options.transition || 'all 0.5s ease') + ', height 0, width 0',
width = $this.innerWidth(),
item_margin = parseInt(options.margin || 0),
item_width = parseInt(options.max_width || options.width || 220),
column_count = Math.max(Math.floor(width/(item_width + item_margin)),1),
left = column_count == 1 ? item_margin/2 : (width % (item_width + item_margin)) / 2,
columns = [];
var parent_height = "0";
if (options.max_width) {
column_count = Math.ceil(width/(item_width + item_margin));
item_width = (width - column_count * item_margin - item_margin)/column_count;
left = item_margin/2;
}
for (var i = 0; i < column_count; i++) {
columns.push(0);
}
for(var i = 0, length = items.length; i< length; i++)
{
var $item = $(items[i]), idx = indexOfSmallest(columns);
$item.css({
width: item_width,
position: 'absolute',
margin: item_margin/2,
top: columns[idx] + item_margin/2,
left: (item_width + item_margin) * idx + left,
transition: transition
});
columns[idx] += $item.innerHeight() + item_margin;
var child_max = $item.position().top+$item.outerHeight();
if(child_max>parent_height) parent_height=child_max;
}
parent_height += item_margin;
$this.css({height: parent_height+'px'});
};
I'm using Handlebars.js template. Gridify only works for
<div class="grid">
{{#each img in images}}
<img {{bind-attr src=img.src_path}}>
{{/each}}
</div>
But when I tried to use <span>
for cross button, gridify doesn't allow the spans over images.
<div class="grid">
{{#each img in images}}
<img {{bind-attr src=img.src_path}}>
<span style="position:absolute;top:0;left:80%;z-index:1;">x</span>
{{/each}}
</div>
In every case (also the given example in 'javascript/example') the height of the container collapse. Would be very nice if this could be fixed!
Hi,
It seems transition does not working on firefox.
Hi,
I just came across your plugin, and it looks really suitable for my projects.
Any idea if it's responsive, and what browsers it works on?
Thanks!
Hi,
Another issue is that it does not consider items border for calculating "top" attribute.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.