问题
So, I'm using Masonry to make a "fluid" layout in my site but now I've encountered a problem involving its hide and reveal methods.
In an event, I'm making this call:
$container.masonry('hide', $(this));
As you can see, I'm using $(this) to tell masonry what element to hide through jquery
But apparently, this method does not work with a jquery element?
The error message in my console looks like this:
Uncaught TypeError: Object #<HTMLElement> has no method 'hide' (masonry.pkgd.min.js:9)
I tried looking in the documentation but all it says about the accepted type is:
$container.masonry( 'hide', items )
items Type: Array of Masonry.Items
What is a Masonry.Item supposed to be? And how do I indicate my element as one?
回答1:
If you read the documentation then you find items are the array of elements.
items Type: Array of Masonry.Items
Try this,
var arr=new Array();
arr.push($(this));
$container.masonry('hide', arr);
回答2:
Add this function
// FIX para Masonry
// goes through all children again and gets bricks in proper order
Outlayer.prototype.publicItemize = function() {
// collection of item elements
return this._itemize( this.element.children );
};
now you can do this
// Get correcto list in correct format
var _list = container.masonry("publicItemize");
// Actions on "_list"
// hide elements
container.masonry("hide", _list);
来源:https://stackoverflow.com/questions/17131080/jquery-masonryhide-element-method-with-a-jquery-element