kombai / freewall

Freewall is a cross-browser and responsive jQuery plugin to help you create grid, image and masonry layouts for desktop, mobile, and tablet...
MIT License
1.85k stars 375 forks source link

How can I make mobile show two columns? #212

Closed xnog closed 8 years ago

xnog commented 8 years ago

Hi,

I have four columns (width: 25%) and on mobile it shows me only one column.

How can I make mobile show two columns?

var wall2 = new Freewall(".products"); wall2.reset({ selector: '.product', animate: true, cellW: 255, cellH: 'auto', onResize: function() { wall2.fitWidth(); } });

.product { width: 276.5px; }

micahstairs commented 8 years ago

What happens if you choose a smaller 'cellW' value?

xnog commented 8 years ago

i still get only one cell on mobile. i tried with 120

xnog commented 8 years ago

Does anyone have an example with mobile and two coluns so I can check what i am doing wrong?

kombai commented 8 years ago

Hi, you can using cellW as a function

cellW: function(container) {
 return container.width() / 2;
}

You can see the source code of this example: http://vnjs.net/www/project/freewall/example/live-size.html Best

PhantomRay commented 8 years ago

I didn't know cellW supports function. I give it a dynamic value according to window.innerWidth.

var width = 236;
if (window.innerWidth <= 320) {
    width = 120;
} else if (window.innerWidth <= 414) {
    width = 150;
} else if (window.innerWidth <= 667) {
    width = 200;
}

var currentWidth = window.innerWidth;
$scope.resetWall = function () {
    wall.reset({
        selector: '.card',
        animate: true,
        cellW: width,
        cellH: 'auto',
        onResize: function () {
            if (currentWidth !== window.innerWidth)
                wall.fitWidth();
        }
    });

    wall.fitWidth();

    wall.container.find('.card img').load(function () {
        wall.fitWidth();
    });
};

Working example at https://collector.im/categories/action-figures

But I feel Kombai's solution is much better.

kombai commented 8 years ago

@dragonfish-au that good too. Thank you 👍