Use Isotope with objects loaded in with XML and jQuery. Is this possible?

断了今生、忘了曾经 提交于 2019-12-01 13:07:41

looks like you are adding your elements to the container after the animation is completed. I think it has to be the other way around: on page ready:

  • do your ajax
  • in the success-callback add the elements to the DOM
  • then initialize isotope (last step in the ajax-success)

edit: to your question in the comment: I'm not sure if I understand what your asking for. Since there is no jsfiddle or something I had to make sum assumptions:

  • your container is empty
  • you load some xml, parse it and generate elements you want to have in isotope
  • your code looks like you initialize isotope on an empty container - then add elements.

my solution:

var $container = $('#container');
var $checkboxes = $('#filters a');

init();

function init(){
    $.get('sites.xml', function (d) {

        $(d).find('site').each(function () {
            var imageUrl = $(this).find('imgurl').text();
            var title = $(this).find('title').text();
            var url = $(this).find('url').text();
            var brief = $(this).find('brief').text();
            var long = $(this).find('long').text();
            var classa = $(this).find('_class').text();

            $('<div class="' + classa + '"></div>').html('<a href="' + url + '"> 
            <img  src="' + imageUrl + '" class="thumbnail" />' + '<h1>' + title + '</h1> 
            </a>').appendTo('#container');

            }); // end each

        initIsotop(); // after adding all elements - init isotop
    }); // end $.get
}

function initIsotop() {
    $container.isotope({
        itemSelector: '.item',
        transformsEnabled: false,    
        animationOptions: {
            duration: 4000,
            easing: 'easeInOutQuad',
            queue: false
        }
    });
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!