brunjo / rowGrid.js

A small, lightweight JavaScript plugin for placing items in straight rows (jQuery and vanilla JS version) – Demo:
http://brunjo.github.io/rowGrid.js/
MIT License
670 stars 78 forks source link

Doesn't work with dynamic elements until a window is resized #20

Closed dave-yang closed 9 years ago

dave-yang commented 9 years ago

Looks like the plug in isn't being activated for dynamic elements. To reproduce the issue try creating elements dynamically, after the plugin is activated (in Jquery's DOM ready function);

var div = document.createElement('div');
$(div).setAttr('class', 'item');

var img = document.createElement('img');
$(img).setAttr('height', 200);

$(div).append(img);

It will only gets activated when you resize the window.

brunjo commented 9 years ago

If you append the dynamically created div to the container you can call $(".container").rowGrid("appended"); to arrange the newly appended div.

Or if you added the new div at the beginning or somewhere else in the container you can just call the plugin again:

var options = {minMargin: 5, maxMargin: 15, itemSelector: ".item", firstItemClass: "first-item"};
$(".container").rowGrid(options);

I hope this helps you.

dave-yang commented 9 years ago

Thanks Bruno!