How to apply a default filter to the container after dynamic insertion of items using Jquery Isotope plugin?

后端 未结 3 1887
清酒与你
清酒与你 2021-01-20 11:11

I\'m using the Isotope Plugin. I have an empty container to which I am adding items on $(document).ready(...

All those items are added correctly and iso

3条回答
  •  别那么骄傲
    2021-01-20 11:41

    If you have something simple like

    
    

    you could just run a function to preset filtering, once the DOM has been fully constructed

    $(function() {
        // Isotope stuff...
        $container.isotope({filter: '.home'});
        // more Isotope stuff...
    });
    

    and Isotope has been initialised. See this modified DeSandro fiddle in which the initial view is filtered to show only the red elements.

    UPDATE Loading the initial content into an empty #container (via Ajax?), you could use the insert method or just hide the #container until all elements have been loaded and sorted. Regarding Ajax and initialising Isotope on success, see also this SO answer here.

提交回复
热议问题