Jquery: 使用jquery元素的masonry('hide',element)方法

4

我使用 Masonry 来制作我的网站的“流体”布局,但现在我遇到了一个问题,涉及它的隐藏和显示方法。

在一个事件中,我进行了如下调用:

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

如您所见,我正在使用$(this)通过jquery告诉masonry需要隐藏哪个元素

但显然,这种方法不能与jquery元素一起使用?

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

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

我尝试在文档中寻找答案,但关于所接受的类型,文档中只有以下内容:
$container.masonry( 'hide', items )

items 类型: Masonry.Items 的数组

Masonry.Item 应该是什么?我如何将我的元素标识为其中之一?

2个回答

4

如果您阅读文档,您会发现itemselementsarray

items 类型:Masonry.Items数组

试试这个:

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

谢谢!它完美地隐藏了我的项目...但是...我正在尝试使用它的对应物'masonry('reveal', arr)',但现在它返回错误"Uncaught TypeError: Object [object Object] has no method 'reveal'" - XuxuBelezA
1
我最终放弃使用插件方法,现在只是使用jQuery标准的.show()和.hide(),然后稍后调用masonry('layout')方法。-.- - XuxuBelezA
哇,谢谢@XuxuBelezA。我一直在寻找一个解决隐藏功能的古怪行为的好方法,你建议只使用jQuery的hide和show真正解决了我的问题,并加快了我的工作效率!虽然这不是技术上的答案,但我认为它应该在这个主题上更加显眼! - thepauljones

0
请添加此函数。
// 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);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接