3

In a nutshell, what I want to achieve using the Angular-masonry directive (http://passy.github.io/angular-masonry/) is something like this: http://codepen.io/desandro/pen/htsui

I have tried a number of different methods, but the bigger div just spreads out over the top of the next div along.

This is the HTML:

<div class="row" ng-controller="DemoCtrl">
        <div class="span12">
            <div masonry >
                <div class="masonry-brick" ng-repeat="brick in bricks">
                     <div ng-class="brick.cssClass"  ng-click="changeBrick($index)">
                        <img ng-src="{{brick.src}}" alt="A masonry brick" >
                        <span>Here is a load of text to see what fits in here and such </span>
                     </div>
                </div>
            </div>
        </div>
    </div>

This is a snippet of the angular code:

app.controller('DemoCtrl', function ($scope, $timeout,$element) {

..

 $scope.changeBrick= function changeBrick(i) {
  $scope.bricks[i].cssClass = 'big';
  $element.masonry();
  $element.masonry('layout');
 }
}

The styles are just this for testing:

.small{
 width: 200px;
 background-color: lime;
}

.big{
 width: 400px;
 background-color: red;
}

Ate the moment, the div just spreads out to right over the top of the next div along - I really want masonry to do its thing and rearrange the other divs.

Divyanshu Maithani
  • 13,908
  • 2
  • 36
  • 47
SnowJon
  • 544
  • 4
  • 4

1 Answers1

0

Try broadcasting the masonry.reload message to get angular-masonry to refresh the layout. I ran into a semi-similar problem and this seems to work: https://stackoverflow.com/a/27967782/3191599

function refresh() {
    common.$timeout(function () { $scope.$broadcast('masonry.reload'); }, 100);
}
Community
  • 1
  • 1
Nate Barbettini
  • 51,256
  • 26
  • 134
  • 147