Jquery:带有jquery元素的masonry(’hide’,element)方法

所以,我正在使用Masonry在我的网站中制作一个“流畅”的布局,但现在我遇到了一个涉及其隐藏和显示方法的问题。

在一个事件中,我正在打这个电话:

$container.masonry('hide', $(this)); 

正如你所看到的,我正在使用$(this)告诉砌体通过jquery隐藏哪些元素

但显然,这种方法不适用于jquery元素?

我的控制台中的错误消息如下所示:

 Uncaught TypeError: Object # has no method 'hide' (masonry.pkgd.min.js:9) 

我尝试查看文档,但所有关于接受类型的说法是:

 $container.masonry( 'hide', items ) 

items类型: Masonry.Items 数组

什么是Masonry.Item应该是什么? 我如何将我的元素指定为一个?

如果您阅读文档,那么您会发现itemselements array

items Type: Array of Masonry.Items

试试这个,

 var arr=new Array(); arr.push($(this)); $container.masonry('hide', arr); 

添加此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 ); }; 

现在你可以做到这一点

 // Get correcto list in correct format var _list = container.masonry("publicItemize"); // Actions on "_list" // hide elements container.masonry("hide", _list);