首页 > 解决方案 > 将 Ajax 与同位素结合使用

问题描述

我正在尝试将项目附加到基于同位素的 div,并且这些项目正在被附加,但附加的项目没有采用 Css(即它们放错了位置)。以下是我的 html & ajax 函数:

div class="main_isotop" id="container"

var grid = $('.main_isotop').isotope({
                    itemSelector: '.item',
                    layoutMode: 'masonry'
                });
$.ajax({

                    url: '/loadmoremedia',
                    type: 'GET',
                    datatype: 'html',
                    data: {
                        }                        },
                    success: function (result) {
                        //var $items = result;
                        $('#lastPhotoId').remove();
                        //$('.main_isotop').append(result);
                        grid.append(result)
                            // add and lay out newly appended elements
                            .isotope('appended', result);
                        processing = false;
                    },
                    error: function (result) {
                        alert("Failed");
                    }
                });

谁能指出缺少什么?欢迎修改。

标签: ajaxjquery-isotope

解决方案


Isotope 有很多方法可以在使用 ajax 等动态添加新内容后计算布局。

你可以试试这样的

$container.isotope('insert', $items)

或者

$container.append( $html ); $container.isotope( 'appended', $html );

一切顺利。:-)


推荐阅读