(function tagCloud() {
var container = $('.tag_cloud_holder'),
container_w = 0,
item = $('button', container);
$(item).data('timer', setInterval(function () {
if (container_w != $(container).innerWidth()) {
container_w = $(container).innerWidth();
resizer();
}
}, 50));
function resizer() {
var temp = {};
$(item).attr('style', '');
$(item).each(function () {
temp[this.offsetTop] = temp[this.offsetTop] || [];
temp[this.offsetTop].push(this);
});
for (var str in temp) {
var items = temp[str],
length = items.length,
items_w = 0,
plus;
// считаем суммарную ширину всех элементов в строке
for (var i = 0; i < items.length; i++) {
items_w += $(items[i]).outerWidth();
}
// делим разницу между шириной контейнера и суммарной шириной элементов строки, на количество элементов
plus = (container_w - items_w) / length;
// это фикс, если ячейки прыгают на следующую строку, попробуйте увеличить множитель
// каждому элементу прибавляем то что получили раньше, и переводим в проценты
for (var i = 0; i < items.length; i++) {
var new_width = ($(items[i]).outerWidth() + plus) / container_w * 100;
if (new_width < 99) new_width -= 2;
else new_width = 100;
$(items[i]).css('width', new_width + '%');
}
}
}
})();
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.