I thought a lot about how to make gridster.js responsive. I found the code snippet in the github issues in gridster and realized that if I ran it at a specific window size and destroyed and restarted the gridster, I could get the effect of the response to the gridster responseivley. Let me show you what I mean -
$(window).resize(function(){
var width = $(window).width();
var columns = "";
if(Modernizr.mq('screen and (max-width:640px)')){
columns = 1;
gridster.destroy();
var tooFar = $('.gridster .gs-w').filter(function () {
return $(this).data('col') > columns;
});
$(tooFar).each(function () {
$(this).attr('data-col', '1');
});
var tooBig = $('.gridster li').filter(function () {
return $(this).data('sizex') > columns;
});
$(tooBig).each(function () {
$(this).attr('data-sizex', columns);
});
$(".gridster ul").gridster({
widget_base_dimensions: [300, 300],
widget_margins: [5, 5],
max_cols: 1,
resize: {
enabled: true
},
draggable: {
handle: '.dragDiv'
},
serialize_params: function ($w, wgd) {
return {
id: $w.attr('id'),
col: wgd.col,
row: wgd.row,
size_x: wgd.size_x,
size_y: wgd.size_y,
}
}
}).data('gridster');
}
});
, 1 ( 4), , re 1 . , , . ( , 3 -2 -1 ). , , , , , .
- , , , .
-, , , , .
!!