gpt4 book ai didi

javascript - Angularjs 与 Packery.js

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:15:52 25 4
gpt4 key购买 nike

试图让 Packery.js 与我正在使用的 angularjs 应用一起工作。

出于某种原因,他们似乎相处得并不融洽。我认为它可以通过 isInitLayout false 设置来解决,但是,仍然没有爱。

这是我的(bootstrap 3)HTML:

<div class="row" class="js-packery" 
data-packery-options='{ "itemSelector": ".packery-item",
"gutter": 10,
"columnWidth": 60,
"isInitLayout": false }'>
<artifact class="packery-item" ng-repeat="(index, thing) in data | limitObjectTo:4" thing="thing"></artifact>
</div>

我开始怀疑是不是因为我使用的 Artifact 指令...

最佳答案

如前所述,您必须制定一个指令来处理 Packery 的使用。

该指令使 Packery 在我正在处理的项目中与 AngularJS 一起工作。

工作 fiddle :http://jsfiddle.net/8P6mf/2/

HTML:

<div class="wrapper">
<div ng-repeat="item in test" danny-packery>
{{item.name}}
</div>
</div>

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();
}
};
}]);

关于javascript - Angularjs 与 Packery.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19498174/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com