var colCount = 0
var colWidth = 0
var margin = 20
var windowWidth = 0
var blocks = []

var $win = $(window)
var $items = null

$win.resize(setupBlocks)

export default function setupBlocks() {
	$items = $('.board-post')
	windowWidth = $win.width()
	colWidth = $items.outerWidth()
	blocks = []
	colCount = Math.floor(windowWidth/(colWidth+margin*2))
	for(var i=0; i<colCount; i++){
		blocks.push(margin)
	}
	positionBlocks()
}

function positionBlocks() {
	$items.each(function(){
		var min = Array.min(blocks)
		var index = $.inArray(min, blocks)
		var leftPos = margin+(index*(colWidth+margin))
		$(this).css({
			'left':leftPos+'px',
			'top':min+'px'
		})
		blocks[index] = min+$(this).outerHeight()+margin
	})	
}

// Function to get the Min value in Array
Array.min = function(array) {
    return Math.min.apply(Math, array)
}
@@ -23,24 +23,43 @@
 olWidth = 0%0A
+var minMargin = 20%0A
 var margin =
@@ -55,25 +55,24 @@
 ar margin = 
-2
 0%0Avar window
@@ -102,29 +102,8 @@
 %5B%5D%0A%0A
-var $win = $(window)%0A
 var 
@@ -118,19 +118,24 @@
  null%0A%0A$
+(
 win
+dow)
 .resize(
@@ -231,19 +231,24 @@
 idth = $
+(
 win
+dow)
 .width()
@@ -335,24 +335,27 @@
 /(colWidth+m
+inM
 argin*2))%0A%09f
@@ -357,15 +357,87 @@
 ))%0A%09
-for(var
+margin = (windowWidth - colWidth*colCount) / colCount - minMargin + 5%0A%09for (let
  i=0
@@ -454,16 +454,17 @@
 nt; i++)
+ 
 %7B%0A%09%09bloc
@@ -696,40 +696,42 @@
 %09%09%09'
-left':leftPos+'px',%0A%09%09%09'top':min
+top': min+'px',%0A%09%09%09'left': leftPos
 +'px

Give columns space-inbetween