提交 | 用户 | 时间
|
58d006
|
1 |
## MixItUp - A CSS3 and jQuery Filter & Sort Plugin |
A |
2 |
|
|
3 |
### What Is MixItUp? |
|
4 |
|
|
5 |
MixItUp is a light-weight but powerful jQuery plugin that provides beautiful animated filtering and sorting of categorized and ordered content. It plays nice with your existing HTML and CSS, making it a great choice for fluid, responsive layouts. It's perfect for portfolios, galleries, blogs, or any categorized or ordered content! |
|
6 |
|
|
7 |
### How does it work? |
|
8 |
|
|
9 |
MixItUp uses jQuery to decide which elements to hide, show or re-position based on your filters, and then applies the power of CSS3 transitions to smoothly animate these elements to their new locations. It's an extremely efficient approach that makes the most of your modern browser's rendering power, and avoids more resource-heavy approaches involving jQuery .animate() and position: absolute. |
|
10 |
|
|
11 |
By not forcing absolute positioning on your design, all elements remain in the document flow and your fluid layout will behave exactly as it normally would - leaving you free to use percentages and media queries to achieve that pixel-perfect responsive design! When MixItUp is finished working its magic, it cleans up its code and gets outta your DOM. |
|
12 |
|
|
13 |
### Which browsers and devices can I use it with? |
|
14 |
|
|
15 |
MixItUp is optimized for the current generation of modern, CSS3-ready browsers. Due to its light-weight and efficient approach, It works beautifully and smoothly on all modern devices including smartphones and tablets. |
|
16 |
|
|
17 |
In older browsers (such as Internet Explorer 9 and below) that do not support CSS3 transitions, MixItUp will degrade gracefully to a simple hide/show filter. By not including extensive jQuery animation fall-backs, we've kept MixItUp ultra-light and optimized for the future of the web. |
|
18 |
|
|
19 |
### How did it begin development? |
|
20 |
|
|
21 |
At Barrel LLC, many of the designs we create for our clients involve pages with responsive grid layouts and filtering between categories. We weren't satisfied with how the existing filtering plugins out there handled percentage-based responsive behavior, and seeing a need for something lighter and more forward-looking, we decided to build our own solution! |
|
22 |
|
|
23 |
### How may I use MixItUp? |
|
24 |
|
|
25 |
You are free to use MixItUp on any commercial or non-commercial project. Just be sure to keep the license information and attribution in the code. |
|
26 |
|
|
27 |
## Getting Started |
|
28 |
|
|
29 |
For the full documentation and list of configuration options please visit out marketing site at [mixitup.io](http://mixitup.io). |
|
30 |
|
|
31 |
MixItUp couldn't be easier to setup. Just follow these simple steps in your HTML, CSS and JavaScript: |
|
32 |
|
|
33 |
### HTML |
|
34 |
|
|
35 |
#### Build Your Container and Content |
|
36 |
|
|
37 |
MixItUp can be applied to any type of elements within a container, such as an unordered list. Your container should have a unique ID (e.g. 'Grid') that we will use to instantiate MixItUp in your JavaScript. By default, MixItUp will apply itself only to elements within your container with the class 'mix', but this can be changed with the 'targetSelector' configuration option. |
|
38 |
|
|
39 |
The filtering categories of each target element should be entered into its class attribute (after the targetSelector class if you are using a class): |
|
40 |
|
|
41 |
<ul id="Grid"> |
|
42 |
<li class="mix dogs"></li> |
|
43 |
<li class="mix cats"></li> |
|
44 |
<li class="mix krakens"></li> |
|
45 |
<li class="mix dogs cats"></li> |
|
46 |
<li ... |
|
47 |
</ul> |
|
48 |
|
|
49 |
Additional alphabetic or numeric HTML5 data attributes for sorting may also be added to your target elements: |
|
50 |
|
|
51 |
<ul id="Grid"> |
|
52 |
<li class="mix dogs" data-name="Abby" data-age="2"></li> |
|
53 |
<li class="mix cats" data-name="Bucky" data-age="9"></li> |
|
54 |
<li class="mix dogs" data-name="Francis" data-age="5"></li> |
|
55 |
<li class="mix krakens" data-name="Kraken" data-age="3987"></li> |
|
56 |
<li ... |
|
57 |
</ul> |
|
58 |
|
|
59 |
#### Build Your Filter Controls |
|
60 |
|
|
61 |
Filtering happens when filter buttons are clicked. By default MixItUp will apply filtering click handlers to any element with the class 'filter', but this can be changed with the the 'filterSelector' configuration option. When a filter category is active, its corresponding filter buttons gets the class 'active', which can be used for styling active buttons. |
|
62 |
|
|
63 |
These buttons could also be part of an unordered list. The desired filter categories of each filter button should be entered as the "data-filter" attribute. See the 'filterLogic' option for details on how MixItUp handles multiple filters. |
|
64 |
|
|
65 |
<ul> |
|
66 |
<li class="filter" data-filter="dogs"></li> |
|
67 |
<li class="filter" data-filter="cats"></li> |
|
68 |
<li class="filter" data-filter="krakens"></li> |
|
69 |
<li class="filter" data-filter="dogs cats"></li> |
|
70 |
</ul> |
|
71 |
|
|
72 |
Alternatively, elements may be filtered directly via javascript with the 'filter' method. |
|
73 |
|
|
74 |
#### Build Your Sort Controls |
|
75 |
|
|
76 |
Sorting happens when sort buttons are clicked. By default MixItUp will apply sorting click handlers to any element with the class 'sort', but this can be changed with the the 'sortSelector' configuration option. |
|
77 |
|
|
78 |
These buttons could also be part of an unordered list, with the data attribute to sort by entered as the "data-sort" attribute, and the order to sort by entered as the "data-order" attribute: |
|
79 |
|
|
80 |
<ul> |
|
81 |
<li class="sort" data-sort="data-name" data-order="desc"></li> |
|
82 |
<li class="sort" data-sort="data-name" data-order="asc"></li> |
|
83 |
<li class="sort" data-sort="data-age" data-order="desc"></li> |
|
84 |
<li class="sort" data-sort="data-age" data-order="asc"></li> |
|
85 |
<li class="sort" data-sort="default" data-order="asc"></li> |
|
86 |
<li class="sort" data-sort="random"></li> |
|
87 |
</ul> |
|
88 |
|
|
89 |
Sorting by 'default' maintains the order that elements are originally entered into the DOM, and is useful for toggling between descending and ascending order, without sorting by a specific attribute. |
|
90 |
|
|
91 |
Alternatively, elements may be sorted directly via javascript with the 'sort' method. |
|
92 |
|
|
93 |
### CSS |
|
94 |
|
|
95 |
If you're not sure where to begin with your styling, check out our boilerplate template and demos. |
|
96 |
|
|
97 |
If you want to go it alone though, here are some dos and don'ts: |
|
98 |
|
|
99 |
#### Dos |
|
100 |
|
|
101 |
Because MixItUp never interferes the flow, width, or height of your elements, the styling and design is completely up to you. Just be sure to make sure your target elements have the following CSS properties in your stylesheet: |
|
102 |
|
|
103 |
#Grid .mix{ |
|
104 |
opacity: 0; |
|
105 |
display: none; |
|
106 |
} |
|
107 |
|
|
108 |
These two styles ensure that there's no FOUC (flash of unstyled content) or showing of hidden target elements before MixItUp instantiates. This way, MixItUp controls the initial loading of your elements, when your page is ready. |
|
109 |
|
|
110 |
You'll probably want to add these two properties only once you've finished designing your layout and you're ready to instantiate MixItUp - otherwise you won't be able to see your elements! |
|
111 |
|
|
112 |
#### Don'ts |
|
113 |
|
|
114 |
Avoid applying styles such as position: absolute or float: left/right to your elements, as doing so removes your elements from the natural flow of the document. If you're looking to build a layout that doesn't follow the natural horizontal documental flow, we recommend David DeSandro's excellent plugin Isotope. MixItUp is intended as a lightweight and modern filter and sort plugin - not a layout tool. |
|
115 |
|
|
116 |
### JavaScript |
|
117 |
|
|
118 |
MixItUp uses the jQuery JavaScript library. Make sure you have jQuery loaded into your project's head before MixItUp: |
|
119 |
|
|
120 |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> |
|
121 |
<script src="js/jquery.mixitup.min.js"></script> |
|
122 |
... |
|
123 |
|
|
124 |
MixItUp is instantiated on your container in your JavaScript like this: |
|
125 |
|
|
126 |
$(function(){ |
|
127 |
|
|
128 |
$('#Grid').mixitup(); |
|
129 |
|
|
130 |
}); |
|
131 |
|
|
132 |
And we're done! |
|
133 |
|
|
134 |
As long as you use the default selectors in your HTML, MixItUp should run straight out of the box. If you're looking to do something more advanced, see our the full documentation on [mixitup.io](http://mixitup.io) for all available configuration options. |