mirror of https://github.com/metafizzy/isotope
Filter & sort magical layouts
http://isotope.metafizzy.co
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
3.1 KiB
80 lines
3.1 KiB
14 years ago
|
---
|
||
|
|
||
|
title: Adding items
|
||
|
category: docs
|
||
14 years ago
|
layout: default
|
||
14 years ago
|
toc:
|
||
|
- { title: addItems method, anchor: additems_method }
|
||
|
- { title: insert method, anchor: insert_method }
|
||
|
- { title: appended method, anchor: appended_method }
|
||
14 years ago
|
- { title: Prepending, anchor: prepending }
|
||
14 years ago
|
- { title: Recommended CSS, anchor: recommended_css }
|
||
14 years ago
|
|
||
|
---
|
||
|
|
||
|
If your application dynamically adds new content, Isotope provides several methods to add items.
|
||
|
|
||
14 years ago
|
[**See Demo: Adding items**](../demos/adding-items.html).
|
||
|
|
||
14 years ago
|
## addItems method
|
||
14 years ago
|
|
||
14 years ago
|
The [`addItems` method](methods.html#additems) 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's it. The new content will _not_ be filtered, sorted, or positioned properly, nor will it be appended to the container element.
|
||
14 years ago
|
|
||
|
{% highlight javascript %}
|
||
|
|
||
|
var $newItems = $('<div class="item" /><div class="item" /><div class="item" />');
|
||
14 years ago
|
$('#container').append( $newItems ).isotope( 'addItems', $newItems );
|
||
14 years ago
|
|
||
|
{% endhighlight %}
|
||
|
|
||
14 years ago
|
## insert method
|
||
14 years ago
|
|
||
14 years ago
|
More likely, you want to use the [`insert` method](methods.html#insert), which does everything that `addItems` misses. `insert` will append the content to the container, filter the new content, sort all the content, then trigger a `reLayout` so all item elements are properly laid out.
|
||
14 years ago
|
|
||
|
{% highlight javascript %}
|
||
|
|
||
|
var $newItems = $('<div class="item" /><div class="item" /><div class="item" />');
|
||
14 years ago
|
$('#container').isotope( 'insert', $newItems );
|
||
14 years ago
|
|
||
|
{% endhighlight %}
|
||
|
|
||
14 years ago
|
## appended method
|
||
14 years ago
|
|
||
14 years ago
|
The [`appended` method](methods.html#appended) is a convenience method triggers `addItems` on new content, then lays out _only the new content_ at the end of the layout. This method is useful if you know you only want to add new content to the end, and **not** use filtering or sorting. `appended` is the best method to use with Infinite Scroll.
|
||
14 years ago
|
|
||
14 years ago
|
[**See Demo: Infinite Scroll**](../demos/infinite-scroll.html).
|
||
|
|
||
14 years ago
|
See also [Infinite Scroll with filtering or sorting](help.html#infinite_scroll_with_filtering_or_sorting)
|
||
14 years ago
|
|
||
|
## Prepending
|
||
|
|
||
|
Because of Isotope's sorting functionality, prepending isn'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 [`reloadItems` method](methods.html#reloaditems). Then trigger a re-layout, with the original DOM order.
|
||
|
|
||
|
{% highlight javascript %}
|
||
|
|
||
|
var $newItems = $('<div class="item" /><div class="item" /><div class="item" />');
|
||
|
$('#container').prepend( $newItems)
|
||
|
.isotope( 'reloadItems' ).isotope({ sortBy: 'original-order' });
|
||
|
|
||
14 years ago
|
{% endhighlight %}
|
||
|
|
||
|
## Recommended CSS
|
||
|
|
||
|
You'll need these styles in your CSS for the reveal animation when adding items.
|
||
|
|
||
|
{% highlight css %}
|
||
|
|
||
|
/**** disabling Isotope CSS3 transitions ****/
|
||
|
|
||
|
.isotope.no-transition,
|
||
|
.isotope.no-transition .isotope-item,
|
||
|
.isotope .isotope-item.no-transition {
|
||
|
-webkit-transition-duration: 0s;
|
||
|
-moz-transition-duration: 0s;
|
||
13 years ago
|
-ms-transition-duration: 0s;
|
||
|
-o-transition-duration: 0s;
|
||
14 years ago
|
transition-duration: 0s;
|
||
|
}
|
||
|
|
||
|
{% endhighlight %}
|