adding-items.html 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>Adding items &middot; Isotope Docs</title>
  6. <!--[if lt IE 9]><script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
  7. <link rel="stylesheet" href="../css/style.css" />
  8. <!-- scripts at bottom of page -->
  9. </head>
  10. <body class="docs ">
  11. <nav id="site-nav">
  12. <h1><a href="../index.html">Isotope</a></h1>
  13. <h2>Docs</h2>
  14. <ul>
  15. <li><a href="../docs/introduction.html">Introduction</a>
  16. <li><a href="../docs/options.html">Options</a>
  17. <li><a href="../docs/methods.html">Methods</a>
  18. <li><a href="../docs/layout-modes.html">Layout modes</a>
  19. <li><a href="../docs/filtering.html">Filtering</a>
  20. <li><a href="../docs/sorting.html">Sorting</a>
  21. <li><a href="../docs/animating.html">Animating</a>
  22. <li class="current"><a href="#content">Adding items</a>
  23. <ul class="toc">
  24. <li><a href="#additems_method">addItems method</a></li>
  25. <li><a href="#insert_method">insert method</a></li>
  26. <li><a href="#appended_method">appended method</a></li>
  27. <li><a href="#prepending">Prepending</a></li>
  28. <li><a href="#recommended_css">Recommended CSS</a></li>
  29. </ul>
  30. </li>
  31. <li><a href="../docs/extending-isotope.html">Extending Isotope</a>
  32. <li><a href="../docs/hash-history-jquery-bbq.html">Hash history with jQuery BBQ</a>
  33. <li><a href="../docs/help.html">Help</a>
  34. <li><a href="../docs/license.html">License</a>
  35. </ul>
  36. <h2>Demos</h2>
  37. <ul>
  38. <li><a href="../demos/basic.html">Basic</a>
  39. <li><a href="../demos/elements-complete.html">Elements Complete</a>
  40. <li><a href="../demos/elements-partial.html">Elements Partial</a>
  41. <li><a href="../demos/layout-modes.html">Layout modes</a>
  42. <li><a href="../demos/filtering.html">Filtering</a>
  43. <li><a href="../demos/sorting.html">Sorting</a>
  44. <li><a href="../demos/relayout.html">reLayout</a>
  45. <li><a href="../demos/adding-items.html">Adding items</a>
  46. <li><a href="../demos/infinite-scroll.html">Infinite Scroll</a>
  47. <li><a href="../demos/images.html">Images</a>
  48. <li><a href="../demos/combination-filters.html">Combination filters</a>
  49. <li><a href="../demos/hash-history.html">Hash history</a>
  50. <li><a href="../demos/fluid-responsive.html">Fluid / responsive</a>
  51. </ul>
  52. <h2>Custom layout modes</h2>
  53. <ul>
  54. <li><a href="../custom-layout-modes/centered-masonry.html">Centered Masonry</a>
  55. <li><a href="../custom-layout-modes/category-rows.html">Category rows</a>
  56. <li><a href="../custom-layout-modes/masonry-corner-stamp.html">Masonry corner stamp</a>
  57. <li><a href="../custom-layout-modes/masonry-gutters.html">Masonry gutters</a>
  58. <li><a href="../custom-layout-modes/spine-align.html">Spine align</a>
  59. </ul>
  60. <h2><a href="../tests/index.html">Tests</a></h2>
  61. </nav> <!-- #site-nav -->
  62. <section id="content">
  63. <h1>Adding items</h1>
  64. <p>If your application dynamically adds new content, Isotope provides several methods to add items.</p>
  65. <p><a href='../demos/adding-items.html'><strong>See Demo: Adding items</strong></a>.</p>
  66. <h2 id='additems_method'>addItems method</h2>
  67. <p>The <a href='methods.html#additems'><code>addItems</code> method</a> adds new content to an Isotope container. This applies the proper styles to the items so they can be positioned and any sorting data is retrieved. But that&#8217;s it. The new content will <em>not</em> be filtered, sorted, or positioned properly, nor will it be appended to the container element.</p>
  68. <div class='highlight'><pre><code class='javascript'><span class='kd'>var</span> <span class='nx'>$newItems</span> <span class='o'>=</span> <span class='nx'>$</span><span class='p'>(</span><span class='s1'>&#39;&lt;div class=&quot;item&quot; /&gt;&lt;div class=&quot;item&quot; /&gt;&lt;div class=&quot;item&quot; /&gt;&#39;</span><span class='p'>);</span>
  69. <span class='nx'>$</span><span class='p'>(</span><span class='s1'>&#39;#container&#39;</span><span class='p'>).</span><span class='nx'>append</span><span class='p'>(</span> <span class='nx'>$newItems</span> <span class='p'>).</span><span class='nx'>isotope</span><span class='p'>(</span> <span class='s1'>&#39;addItems&#39;</span><span class='p'>,</span> <span class='nx'>$newItems</span> <span class='p'>);</span>
  70. </code></pre>
  71. </div>
  72. <h2 id='insert_method'>insert method</h2>
  73. <p>More likely, you want to use the <a href='methods.html#insert'><code>insert</code> method</a>, which does everything that <code>addItems</code> misses. <code>insert</code> will append the content to the container, filter the new content, sort all the content, then trigger a <code>reLayout</code> so all item elements are properly laid out.</p>
  74. <div class='highlight'><pre><code class='javascript'><span class='kd'>var</span> <span class='nx'>$newItems</span> <span class='o'>=</span> <span class='nx'>$</span><span class='p'>(</span><span class='s1'>&#39;&lt;div class=&quot;item&quot; /&gt;&lt;div class=&quot;item&quot; /&gt;&lt;div class=&quot;item&quot; /&gt;&#39;</span><span class='p'>);</span>
  75. <span class='nx'>$</span><span class='p'>(</span><span class='s1'>&#39;#container&#39;</span><span class='p'>).</span><span class='nx'>isotope</span><span class='p'>(</span> <span class='s1'>&#39;insert&#39;</span><span class='p'>,</span> <span class='nx'>$newItems</span> <span class='p'>);</span>
  76. </code></pre>
  77. </div>
  78. <h2 id='appended_method'>appended method</h2>
  79. <p>The <a href='methods.html#appended'><code>appended</code> method</a> is a convenience method triggers <code>addItems</code> on new content, then lays out <em>only the new content</em> at the end of the layout. This method is useful if you know you only want to add new content to the end, and <strong>not</strong> use filtering or sorting. <code>appended</code> is the best method to use with Infinite Scroll.</p>
  80. <p><a href='../demos/infinite-scroll.html'><strong>See Demo: Infinite Scroll</strong></a>.</p>
  81. <p>See also <a href='help.html#infinite_scroll_with_filtering_or_sorting'>Infinite Scroll with filtering or sorting</a></p>
  82. <h2 id='prepending'>Prepending</h2>
  83. <p>Because of Isotope&#8217;s sorting functionality, prepending isn&#8217;t as straight forward as might expect. However, it can be replicated fairly easy. After prepending new content to the container, you can re-collect all the item elements and update their sorting order with the <a href='methods.html#reloaditems'><code>reloadItems</code> method</a>. Then trigger a re-layout, with the original DOM order.</p>
  84. <div class='highlight'><pre><code class='javascript'><span class='kd'>var</span> <span class='nx'>$newItems</span> <span class='o'>=</span> <span class='nx'>$</span><span class='p'>(</span><span class='s1'>&#39;&lt;div class=&quot;item&quot; /&gt;&lt;div class=&quot;item&quot; /&gt;&lt;div class=&quot;item&quot; /&gt;&#39;</span><span class='p'>);</span>
  85. <span class='nx'>$</span><span class='p'>(</span><span class='s1'>&#39;#container&#39;</span><span class='p'>).</span><span class='nx'>prepend</span><span class='p'>(</span> <span class='nx'>$newItems</span><span class='p'>)</span>
  86. <span class='p'>.</span><span class='nx'>isotope</span><span class='p'>(</span> <span class='s1'>&#39;reloadItems&#39;</span> <span class='p'>).</span><span class='nx'>isotope</span><span class='p'>({</span> <span class='nx'>sortBy</span><span class='o'>:</span> <span class='s1'>&#39;original-order&#39;</span> <span class='p'>});</span>
  87. </code></pre>
  88. </div>
  89. <h2 id='recommended_css'>Recommended CSS</h2>
  90. <p>You&#8217;ll need these styles in your CSS for the reveal animation when adding items.</p>
  91. <div class='highlight'><pre><code class='css'><span class='c'>/**** disabling Isotope CSS3 transitions ****/</span>
  92. <span class='nc'>.isotope.no-transition</span><span class='o'>,</span>
  93. <span class='nc'>.isotope.no-transition</span> <span class='nc'>.isotope-item</span><span class='o'>,</span>
  94. <span class='nc'>.isotope</span> <span class='nc'>.isotope-item.no-transition</span> <span class='p'>{</span>
  95. <span class='o'>-</span><span class='n'>webkit</span><span class='o'>-</span><span class='n'>transition</span><span class='o'>-</span><span class='n'>duration</span><span class='o'>:</span> <span class='m'>0s</span><span class='p'>;</span>
  96. <span class='o'>-</span><span class='n'>moz</span><span class='o'>-</span><span class='n'>transition</span><span class='o'>-</span><span class='n'>duration</span><span class='o'>:</span> <span class='m'>0s</span><span class='p'>;</span>
  97. <span class='n'>transition</span><span class='o'>-</span><span class='n'>duration</span><span class='o'>:</span> <span class='m'>0s</span><span class='p'>;</span>
  98. <span class='p'>}</span>
  99. </code></pre>
  100. </div>
  101. <footer>
  102. Isotope by <a href="http://desandro.com">David DeSandro</a> / <a href="http://metafizzy.co">Metafizzy</a>
  103. </footer>
  104. </section> <!-- #content -->
  105. </body>
  106. </html>