有什么方法可以在Angular中实现jQuery的Quicksand plugin吗?也许有一个实现,但是我似乎找不到它。
也许这样做的策略会对我有所帮助,因为流沙先获取一个列表,然后将新列表作为参数接收,但是使用Angular的数据重新渲染方式,我不知道该怎么做。
最佳答案
我使用石工指令+ ng-animate实现了类似的输入/离开动画,这是仅CSS动画的演示(带有chrome供应商前缀的CSS):
http://jsfiddle.net/g/3SH7a/
指令:
angular.module('app', [])
.directive("masonry", function () {
var NGREPEAT_SOURCE_RE = '<!-- ngRepeat: ((.*) in ((.*?)( track by (.*))?)) -->';
return {
compile: function(element, attrs) {
// auto add animation to brick element
var animation = attrs.ngAnimate || "'masonry'";
var $brick = element.children();
$brick.attr("ng-animate", animation);
// generate item selector (exclude leaving items)
var type = $brick.prop('tagName');
var itemSelector = type+":not([class$='-leave-active'])";
return function (scope, element, attrs) {
var options = angular.extend({
itemSelector: itemSelector
}, attrs.masonry);
// try to infer model from ngRepeat
if (!options.model) {
var ngRepeatMatch = element.html().match(NGREPEAT_SOURCE_RE);
if (ngRepeatMatch) {
options.model = ngRepeatMatch[4];
}
}
// initial animation
element.addClass('masonry');
// Wait inside directives to render
setTimeout(function () {
element.masonry(options);
element.on("$destroy", function () {
element.masonry('destroy')
});
if (options.model) {
scope.$apply(function() {
scope.$watchCollection(options.model, function (_new, _old) {
if(_new == _old) return;
// Wait inside directives to render
setTimeout(function () {
element.masonry("reload");
});
});
});
}
});
};
}
};
})
关于javascript - AngularJS流沙,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16004569/