jquery - divide a single list in a number of columns but is not in order -


here code

var cols = 3; var container = $('ul'); var items = container.find('li'); var itemspercol = math.ceil(items.length / cols); var stack = [];  (var = 0; < itemspercol; i++) {     (var k = 0; k < cols; k++) {         stack.push(items[i + (itemspercol * k)]);     } } items.css({     float:'left',     width:math.floor(container.width() / cols) }); container.html(stack).append($('<br>').css({clear:'both'})); 

there 16 lists in there, , not in order when make 15 list in order

here demo

i need in order in anyway possible because list added.

try this:

var cols = 3; var container = $('ul'); var items = container.find('li'); var itemspercol = math.ceil(items.length / cols); var stack = [];  var containerwidth = container.width(); (var = 0; < itemspercol; i++) {     (var k = 0; k < cols; k++) {         if((i + (itemspercol * k)) < items.length)         {             var item = items[i + (itemspercol * k)];             item.style.width = containerwidth / cols + 'px';             item.style.float = 'left';             stack.push(item);             }         else         {             var item = stack.pop(item);             item.style.width = ((containerwidth / cols) * k) + 'px';             stack.push(item);            }     } }  container.html(stack).append($('<br>').css({clear:'both'})); 

fiddle


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -