There is a field with blocks that can be moved and resized by http://jsfiddle.net/qqzvjvfx/24/ Angular-gridster.js and flexbox .
Code example:
<div ng-app="someApp" ng-controller="someCtrl"> <div gridster="gridsterOpts"> <ul> <li class="" gridster-item="block" ng-repeat="block in sorted_blocks"> <div class="panel panel-default"> <div class="panel-heading">{{ block.title }}</div> <div class="panel-content image-responsive" ng-style="{'background-image':'url(' + block.image + ')'}"></div> </div> </li> </ul> </div> </div> Angular Controller:
angular.module('someApp', ['gridster']).controller('someCtrl', function ($scope, $http) { $scope.gridsterOpts = { resizable: { enabled: true }, columns: 4, rows: 16, minRows: 4, margins: [0,0], floating: false }; $scope.sorted_blocks = [{ id: 1, sizeX: 1, sizeY: 1, image: 'http://i.imgur.com/NI1Xm16.jpg', title: 'title1', row: 1, col: 2 }, { id: 2, sizeX: 2, sizeY: 1, image: 'http://i.imgur.com/x6qmeUY.jpg', title: 'title2', row: 0, col: 0 }]; }); Css:
.panel { display: flex; flex-flow: column wrap; height: 100%; } .panel .panel-content { flex-grow: 1; } .image-responsive { background-size: contain; background-repeat: no-repeat; } It is necessary to add a grid to the field on which the blocks move, for example, as in inkscape or just this .
Suppose a field has 4 columns and from 4 to 16 lines. We display 4 vertical lines and from 4 to 16 horizontal (depending on the size of the displayed area). And if, for example, a block has a size of 1x1, then for any window size this block should clearly occupy 1 cell in the grid, if 3x2, then three cells horizontally, and 2 vertically, respectively. With other block sizes similarly.
I am trying to do it through the tables: http://jsfiddle.net/qqzvjvfx/18/ But how to take into account the fact that the field can increase vertically? Those. rows are added to it, respectively, rows should also be added to the grid table. Now the table is simply stretched vertically.
Through background-image - if I understand correctly, I need to use background-size: cover . But vertically the field can increase, respectively, it is necessary to add a background height, and not stretch. Here I added a div instead of the table, how can I screw the background to this diva correctly so that the background horizontally scales (stretched) depending on the width of this div (and the width of the field on which the blocks move) and repeated vertically?
I also tried to find some built-in functionality in angular-gridster.js , because it highlights the areas at the moment of dragging the block, but the searches have not yet been crowned with success.
Specification: On the grid, you must also select a certain area of the frame.
The size of the region is known in advance — in cells, not in px. Therefore, based on this, the use of tables is more convenient in theory.
Update: A variant with a table and a dynamic update of the number of lines http://jsfiddle.net/qqzvjvfx/26/ - I track changes in blocks, but the block changes its position at the moment of release, and the field height increases "just in case" in advance, t. e. it is necessary to track not resize / relocation of blocks, but resize of the common gridster container.
Update 2: http://jsfiddle.net/sfn57eyh/1/ that the problem of building a grid is that it is necessary to know the current number of container cells in height, since it may change. in this example, because of this, the height of the grid cells is twitching.