How to bind a dynamic DIV to Jquery Masonry plugin?

后端 未结 3 1910
借酒劲吻你
借酒劲吻你 2021-01-20 16:25

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

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

I also have some static links that onclic

3条回答
  •  醉话见心
    2021-01-20 16:41

    You are loading it like:

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

    Ok, so you've defined the masonry options. Now, right after that, let's create a function and bind some events:

    var masonryUpdate = function() {
        setTimeout(function() {
            $('#primary').masonry();
        }, 500);
    }
    $(document).on('click', masonryUpdate);
    $(document).ajaxComplete(masonryUpdate);
    

    Never worry about it again!

提交回复
热议问题