Is there any way to implement jQuery's Quicksand plugin in Angular? Perhaps there is an implementation but I can't seem to find it.
Perhaps a strategy to do it would help me because quicksand takes a list and then receives as a parameter the new list, but with Angular's way of re-rendering data I have no idea how to do that.
Is there any way to implement jQuery's Quicksand plugin in Angular? Perhaps there is an implementation but I can't seem to find it.
Perhaps a strategy to do it would help me because quicksand takes a list and then receives as a parameter the new list, but with Angular's way of re-rendering data I have no idea how to do that.
Share edited Apr 20, 2013 at 11:32 GFoley83 3,5692 gold badges35 silver badges48 bronze badges asked Apr 14, 2013 at 21:32 arg20arg20 4,9911 gold badge54 silver badges75 bronze badges 1-
as with any other DOM manipulation plugin, need to initialize it within an angular directive. Wrap your code in
$timeout
if angular will be creating theLI
elements such as withng-repeat
– charlietfl Commented Apr 14, 2013 at 22:08
2 Answers
Reset to default 8I implemented something similar using a masonry directive + ng-animate for enter/leave animations, here's a CSS animation only demo (with chrome vendor prefixed CSS):
http://jsfiddle/g/3SH7a/
The directive:
angular.module('app', [])
.directive("masonry", function () {
var NGREPEAT_SOURCE_RE = '<!-- ngRepeat: ((.*) in ((.*?)( track by (.*))?)) -->';
return {
pile: 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");
});
});
});
}
});
};
}
};
})
You need to add a directive to do this.
So with just jQuery, you'd have:
JS
$('#source').quicksand( $('#destination li') );
HTML
<ul id="source">
<li data-id="iphone">iOS</li>
<li data-id="android">Android</li>
<li data-id="winmo">Windows Phone 7</li>
</ul>
<ul id="destination" class="hidden">
<li data-id="macosx">Mac OS X</li>
<li data-id="macos9">Mac OS 9</li>
<li data-id="iphone">iOS</li>
</ul>
With Angular you could do:
JS
yourApp.directive('jqQuicksand', function(){
var linkFn = function(scope,element,attrs){
// element here = $(this)
// bind your plugin or events (click, hover etc.) here
element.quicksand( $(attrs.jqQuicksand) );
}
return {
restrict:'A',
scope: {},
link: linkFn
}
});
HTML
<ul data-jq-quicksand="#destination li" id="source">
<li data-id="iphone">iOS</li>
<li data-id="android">Android</li>
<li data-id="winmo">Windows Phone 7</li>
</ul>
<ul id="destination" class="hidden">
<li data-id="macosx">Mac OS X</li>
<li data-id="macos9">Mac OS 9</li>
<li data-id="iphone">iOS</li>
</ul>
Note, this is untested but should be ok.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745060533a4608938.html
评论列表(0条)