Angularjs with Packery.js

前端 未结 2 1368
时光取名叫无心
时光取名叫无心 2021-02-06 18:03

Trying to get Packery.js working with an angularjs app I\'m working with.

For some reason they don\'t seem to play nice together. I th

2条回答
  •  我在风中等你
    2021-02-06 18:43

    As mentioned earlier, you have to make a directive that handles the use of Packery.

    This directive made Packery work with AngularJS in the project I am working on.

    Working fiddle: http://jsfiddle.net/8P6mf/2/

    HTML:

    {{item.name}}

    JavaScript:

    var dannyPackery = app.directive('dannyPackery', ['$rootScope', function($rootScope) {
        return {
            restrict: 'A',
            link: function(scope, element, attrs) {
                console.log('Running dannyPackery linking function!');
                if($rootScope.packery === undefined || $rootScope.packery === null){
                    console.log('making packery!');
                    $rootScope.packery = new Packery(element[0].parentElement, {columnWidth: '.item'});
                    $rootScope.packery.bindResize();
                    $rootScope.packery.appended(element[0]);
                    $rootScope.packery.items.splice(1,1); // hack to fix a bug where the first element was added twice in two different positions
                }
                else{
                    $rootScope.packery.appended(element[0]);
                }
                $rootScope.packery.layout();
            }
        };
    }]);
    

提交回复
热议问题