73 | Released under the MIT License.
74 | Source on Github (changelog).
75 | Compatible with jQuery 1.7.0+ in Firefox, Safari, Chrome, Opera, Internet Explorer 7+. No dependencies except the jQuery library.
76 | A vanilla JavaScript version is available, which works down to IE8.
77 |
78 |
79 |
Ridiculously tiny: 1.4 kB of JavaScript - less than 0.7 kB gzipped
80 |
Source images/objects can have any size
81 |
Works with more than just images, e.g. videos, iframes and plain text
82 |
Responsive
83 |
Equal margins between images controlled via CSS
84 |
No cropping or reordering
85 |
AJAX ready, e.g. for infinite scrolling
86 |
Support for lazy loading of images and iframe contents
87 |
Layout options to control e.g. the maximum number of rows - or whether or not to display an incomplete (last) row.
88 |
89 |
90 | This plugin was developed by and for Pixabay.com - an international repository for free Public Domain images.
91 | We have implemented this plugin in production and we share this piece of software - in the spirit of Pixabay - freely with others.
92 |
93 |
94 |
Live Demo
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
Usage
119 |
120 | Include the stylesheet jquery.flex-images.css in the <head> section of your HTML document - and the JavaScript file jquery.flex-images.min.js after loading jQuery.
121 | flexImages accepts settings from an object of key/value pairs.
122 |
125 | To update any settings or to reload modified content, simply re-initialize flexImages again on the appropriate container.
126 | The plugin automatically prevents multiple bindings to one and the same element.
127 | This may be used for content that gets modified later on via AJAX.
128 |
129 |
130 |
Settings
131 |
132 |
Property
Default
Description
133 |
container
'.item'
Selector of the individual image/object containers.
134 |
object
'img'
Selector of the image/object inside a container.
135 |
rowHeight
180
Maximum height of a row.
136 |
maxRows
null
Maximum number of rows to display. Images/Objects exceeding this row are hidden.
162 | Each image must be wrapped inside a container element. The container must have a width (data-w) and height (data-h) attribute set that corresponds to the image's/object's original dimension.
163 |
164 |
JavaScript code
165 |
166 |
$('.flex-images').flexImages({rowHeight: 140});
167 |
168 |
169 | How it works: The plugin dynamically changes the width and height of all containers.
170 | The images themselves have their height and width set to 100%.
171 | Thus, each image takes up the full space inside its container.
172 |
173 |
174 | This architecture enables a very flexible grid layout that works with more than just images.
175 | E.g. objects may be placed on top of the images via absolute positioning. Or instead of images, the containers may be filled with videos or even plain text.
176 |
177 |
178 |
More Examples
179 |
Please take a look at the source code of this page to see how these demos work.
180 |
181 |
1. Fixed number of two complete rows with lazy loading of images; only images that are actually visible are retrieved from the server:
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 | For lazy loading of images or iframes, it's required to use a "blank.gif" pixel as the source of all images. The actual source URL must be given in a data-src attribute of the image.
197 | On init, the plugin will replace the dummy src attribute (blank.gif) with the actual source URL for all visible images.
198 |
199 |
200 |
2. A fluid grid with video content and only full rows:
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
3. Showing a title underneath + less margin between images:
214 |
215 |
216 |
217 |
Caption 1
218 |
219 |
220 |
221 |
Caption 2
222 |
223 |
224 |
225 |
Caption 3
226 |
227 |
228 |
229 |
Caption 4
230 |
231 |
232 |
233 |
Caption 5
234 |
235 |
236 |
237 |
4. Overlaying caption - could be a link or a button, as well:
238 |
239 |
240 |
241 |
Caption 1
242 |
243 |
244 |
245 |
Caption 2
246 |
247 |
248 |
249 |
Caption 3
250 |
251 |
252 |
253 |
Caption 4
254 |
255 |
256 |
257 |
Caption 5
258 |
259 |
260 |
261 |
5. Cut off parts of the images, e.g. a Shutterstock ID:
Original (uncut) first image with Shutterstock ID at the bottom:
285 |
286 |
287 |
288 |
289 |
290 | This plugin is used in production on Pixabay.com,
291 | where you can see flexImages at work in various locations and with all available options.
292 | Please report any bugs and issues at the GitHub repositiory.
293 |