Passy / Masonry单列,当第一个div为大宽度时

时间:2015-11-06 18:50:46

标签: javascript jquery html css masonry

我使用了passy创建的角度砌体指令,当第一个元素具有几乎100%的宽度时,我遇到了问题。在这种情况下,所有元素合并在一个列中,否则我认为行为是正常的。

我创造了一个傻瓜,看看有没有人可以帮助我。 http://plnkr.co/edit/P8kVidzDV97U7mslECJJ?p=preview

<div ng-controller="CarOperatingPanelCtrl">
    <div class="one-column">
        <div class="two-column">
            <label class="item item-input item-stacked-label">
                <span class="input-label"> Width:</span>
                <input type="number" ng-model="carOperatingPanel.width" value="{{carOperatingPanel.width}}" placeholder="mm" />
            </label>
        </div>
        <div class="two-column">
            <label class="item item-input item-stacked-label">
                <span class="input-label"> Height:</span>
                <input type="number" ng-model="carOperatingPanel.height" value="{{carOperatingPanel.height}}" placeholder="mm" />
            </label>
        </div>
    </div>
    <ul class="draggable-objects">
        <li ng-repeat="obj in draggableObjects">
            <div ng-drag="true" ng-drag-data="obj" data-allow-transform="true"> {{obj.name}} </div>
        </li>
    </ul>

    <div masonry check-last ng-drop="true" ng-drop-success="onDropComplete1($data,$event)">
        <div class="masonry-brick" ng-repeat="obj in droppedObjects1"
             flexible-dimensions
             ng-drag="true" 
             ng-drag-data="obj" 
             ng-drag-success="onDragSuccess1($data,$event)" 
             >
        {{obj.name}}
        </div>
    </div>

 angular.module('starter', ['ngDraggable','wu.masonry'])
.controller('CarOperatingPanelCtrl', function ($scope ) {

$scope.carOperatingPanel = {};
$scope.carOperatingPanel.width = 100;
$scope.carOperatingPanel.height = 200;

$scope.draggableObjects = [{ name: '1', width: 20, height: 20 },
    { name: '2', width: 20, height: 20 },
    { name: '3', width: 20, height: 20 },
    { name: '4', width: 20, height: 20 },
    { name: '5', width: 20, height: 20 },
    { name: '6', width: 20, height: 40 },
    { name: '7', width: 40, height: 20 },
    //{ name: '8', width: 80, height: 40 }
];
$scope.droppedObjects1 = [{ name: '8', width: 80, height: 40 }];

$scope.onDropComplete1 = function (data, evt) {

    var index = $scope.droppedObjects1.indexOf(data);
    if (index == -1)
        $scope.droppedObjects1.push(data);
}
$scope.onDragSuccess1 = function (data, evt) {

    //debugger;
    //console.log("133", "$scope", "onDragSuccess1", "", evt);
    var index = $scope.droppedObjects1.indexOf(data);
    if (index > -1) {
        $scope.droppedObjects1.splice(index, 1);
    }
}
var inArray = function (array, obj) {
    var index = array.indexOf(obj);
}

})
.directive('flexibleDimensions', function ($document) {
return function (scope, element, attr) {

    element.css({
        //0,1cm 1mm
        'margin': (((element.parent()[0].offsetWidth * 1) / scope.carOperatingPanel.width) / 2) + 'px',
        width: ((element.parent()[0].offsetWidth * scope.obj.width) / scope.carOperatingPanel.width) + 'px',
        height: ((element.parent()[0].offsetHeight * scope.obj.height) / scope.carOperatingPanel.height) + 'px'
    });

};
});

我使用ngDraggable将元素推送到放置区域并重新组织它们。为了更好地理解默认情况,我已经选择了最大的div。

如果有人看到不应该出现的事情,请告诉我。 感谢

1 个答案:

答案 0 :(得分:0)

here所述,Angular JS Masonry Directive使用第一个元素的大小来计算默认列宽,除非存在column-width属性。我不知道您想要实现什么,但您可能想尝试设置该属性以使列宽不变。