Jquery: masonry('hide',element) method with a jquery element

血红的双手。 提交于 2019-12-10 08:21:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!