dio-v
8/14/2013 - 9:40 AM

Columnize script door Dio

Columnize script door Dio

//1.in welke container moeten elementen moeten verdeeld worden?
//2.welke elementen in deze container moeten verdeeld worden?
//3.hoeveel kolommen wil je? Zet 0 als de hoogte per column belangrijker is.
//4.hoe hoog mogen de kolommen maximaal zijn
//5 welke class moeten de columns krijgen
//columnize('.footerLinks', 'a', 3,0, 'columns four');
function columnize(el1, el2, el3, el4, el5) {
    var vCol = 0; //aantal kolommen
    var vCont = $(el1); //container
    var el2 = el2;
    var numcols = parseFloat(el3);//aantal kolommen
    var maxH = parseFloat(el4);//of maximum hoogte

    vCont.each(function () {
        //console.log('------------------nieuwe ul');
        var th = $(this);
        th.css({ 'display': 'block', 'visibility': 'visible' });
        var vEl = th.children(el2);
        var tempH = 0;
        var vtotH = 0;
        var vAverage = th.outerHeight(true) / numcols;
        //console.log(th.outerHeight(true) + ' / ' + vAverage);
        if (numcols > 0) {

            vEl.each(function () {
                var th2 = $(this);
                //console.log(th2.text() + ' = ' + th2.outerHeight(true));
                th2.addClass('col' + vCol);
                vtotH = vtotH + th2.outerHeight(true) - 1;
                if (vtotH >= vAverage) {
                    //console.log('>split hier');
                    vtotH = 0;
                    vCol++;
                }
            });
        } else {
            vEl.each(function () {
                var th2 = $(this);
                th2.addClass('col' + vCol);
                tempH = tempH + th2.outerHeight(true) - 1;
                if (tempH > maxH) {
                    tempH = 0;
                    vCol++;
                }
            });
        }
        th.css({ 'display': 'none', 'visibility': 'hidden' });
        vCol++;

    });
    for (var i = 0; i <= vCol; i++) {
        vCont.find('.col' + i).wrapAll('<div class="' + el5 + '">');
    }

};