如何将动态DIV绑定到Jquery Masonry插件? [英] How to bind a dynamic DIV to Jquery Masonry plugin?

查看:92
本文介绍了如何将动态DIV绑定到Jquery Masonry插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的HTML中有一些DIV,可以使用AJAX动态加载.

I have some DIV's in my HTML that I load dynamically using AJAX.

$("#workPanel").load("ex.html");

我还有一些onclick静态链接,称为JQUery砌体,可以对这些动态DIV进行混洗.

I also have some static links that onclick, call the JQUery masonry to shuffle these dynamic DIV's..

            $('#filtering-nav li.1 a, li.2 a, li.3 a').click(function(){
               $('#primary').masonry();

                 return false;
              });

$('#primary').masonry({
            columnWidth: 100, 
            itemSelector: '.box:not(.invis)',
            animate: true,
            animationOptions: {
            duration: speed,
            queue: false
            }
        });

第一次加载页面后,改组工作正常,但是在更新动态DIV时,改组不再起作用.我猜测live()或bind()函数需要在某个地方调用,但是我不知道绑定的方式和位置. 请在这里帮助我.

The shuffling works fine after the first time the page loads, but when the dynamic DIV's are updated, the shuffling does not work anymore. I am guessing the live() or bind() function needs to be called somewhere, but I don't know how and where the binding needs to be done. Please help me out here.

提前谢谢!

推荐答案

以下是将项目动态添加到砌体收藏中的示例:

Here is an example of adding items dynamically to a masonry collection:

http://masonry.desandro.com/demos/adding-items.html

基本上,您需要调用重新加载"砌体选项.

Basically, you need to call the "reload" masonry option.

例如,将jQuery项目"newElement"插入#holder div:

For example to insert the jQuery item "newElement" into the #holder div:

jQuery("#holder").prepend(newElement).masonry('reload')

这篇关于如何将动态DIV绑定到Jquery Masonry插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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