使用jQuery砌筑追加 [英] Using jquery append with masonry

查看:100
本文介绍了使用jQuery砌筑追加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这样的:

$('#loadmore').click(function() {
$.ajax({
   url: 'includes/loadmorebuilds.php',
   success: function(html) {
      $("#content").append(html);
   }
});
});

要装载更多的物品进入这与jQuery的砖石排序的容器。他们被追加然而,当他们不遵循其余项目并打破砌筑风格。

To load more items into a container which is sorted with jquery masonry. However when they are appended they do not follow the rest of the items and break the masonry style.

新的项目工作作为一个砖石布局,但他们就是不从第一批继续。他们开始有自己的行。

The new items work as a masonry layout, but they just dont continue on from the first ones. They start there own line.

我已经搜查,发现在其网站上的信息:

I have searched and found this information on their site:

msnry.appended( elements )
// or with jQuery
$container.masonry( 'appended', elements )

我只需要帮我修改原始脚本,使追加项目砌筑工作。

I just need help modifying my original script to make the appended items work with masonry.

谢谢,克雷格。

推荐答案

你可以做的是你进入的HTML追加到砌体容器,然后'通知'砌筑了。看看这个小提琴。因此,在你的榜样,您的成功回调可能看起来是这样的:

What you can do is append your incoming html to the masonry container and then 'inform' masonry about it. Take a look at this fiddle. So in your example, your success callback could look something like:

//...      
success: function(html) {
    var content = $("#content"),
        elements = $(html); 
        // would make sense to reference your masonry container through 
        // a variable used earlier in the script, but that should work too
        content.append(html).masonry('appended', elements);
}
//...

有一些其他的方法可以做到这一点,但它应该足够你所描述的。最重要的是,你传递是 '类型元素:元素,节点列表,或元素的数组 ,所以你可能要检查你实际接收的内容。

There are some other ways to do this, but it should suffice for what you described. What's important is that you pass elements that are of 'Type: Element, NodeList, or Array of Elements', so you might want to check what you're actually receiving.

这篇关于使用jQuery砌筑追加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆