Copyright (c) Devjam / SHIFTBRAIN INC.
Licensed under the MIT license.
https://github.com/devjam
http://devjam.github.com/jquery.cram.js/
jquery.js
jquery.easing.js // on use ease
itemSelector : "*", cellWidth : 100, cellHeight : 10, marginWidth : 20, marginHeight : 20, isWindowResizeUpdate : true, isAutoLayout : true, isDrawSpace : false, animation : { delayEach : 0, duration : 0, ease : null }
$("#wrapper").cram({ itemSelector : ".item", cellWidth : 100, cellHeight : 100, marginWidth : 20, marginHeight : 20, animation : { duration : 100, ease : "ExpoOut" } });
change options
itemSelector : "*", cellWidth : 100, cellHeight : 10, marginWidth : 20, marginHeight : 20, isWindowResizeUpdate : true, isAutoLayout : true, isDrawSpace : false, animation : { delayEach : 0, duration : 0, ease : null }
$("#wrapper").cram.setOptions({ cellWidth : 100, cellHeight : 100, })
calculate masonry layout
update area width, area height, items position, spaces
trigger "onUpdate" on calculated.
null
$("#wrapper").cram.update();
return items array, spaces array, layout area width and height
null
items: [ { element : DOM, x : Number, y : Number, width : Number, height : Number }, ... ], spaces: [ { x : Number, y : Number, width : Number, height : Number }, ... ], area: { width : Number, height : Number }
var data = $("#wrapper").cram.getData(); var items = data.items; var spaces = data.spaces; var areasize = data.area; var areaWidth = areasize.width; var areaHeight = areasize.height;
dispatch on updated.
$("#wrapper").bind("cram.update", function() { var items = $(this).data("items"); var spaces = $(this).data("spaces"); var areasize = $(this).data("area"); });
only calculation operation
*jquery.js
confing : { itemSelector : "*", cellWidth : 100, cellHeight : 10, marginWidth : 20, marginHeight : 20, isWindowResizeUpdate : true, isAutoLayout : true, isDrawSpace : false, }, width, // Number list[array], // inner items callback // function
list array [
DOM,
...
]or
[ { element : DOM, x : Number, // position fixed y : Number, // position fixed width : Number, height : Number }, ... ]
var opt = null; var width = 800; var list = $(".item"); var cramlist = new cram(opt, width, list, function(data){ console.log data.items; console.log data.spaces; console.log data.area; });
object return to callback function parameters
items array
[ { element : DOM, x : Number, // position fixed y : Number, // position fixed cols : Number, rows : Number width : Number, height : Number }, ... ]
spaces array
[ { x : Number, y : Number, width : Number, height : Number }, ... ]
layout area width and height
{ width : Number, height : Number }
change options
itemSelector : "*", cellWidth : 100, cellHeight : 10, marginWidth : 20, marginHeight : 20, isWindowResizeUpdate : true, isAutoLayout : true, isDrawSpace : false,
var cramlist = new cram(); cramlist.setOptions({ cellWidth : 100 })
make items list, spaces list and area size
width, // Number list[array], // inner items callback // function
list array
[ DOM, ... ]
or
[ { element : DOM, x : Number, y : Number, width : Number, height : Number }, ... ]
var width = 800; var list = $(".item"); var cramlist = new cram(); cramlist.getData(width, list, function(data){ console.log data.items; console.log data.spaces; console.log data.area; });
object
items array
[ { element : DOM, x : Number, y : Number, cols : Number, rows : Number width : Number, height : Number }, ... ]
spaces array
[ { x : Number, y : Number, width : Number, height : Number }, ... ]
layout area width and height
{ width : Number, height : Number }