├── blank.gif ├── bower.json ├── demo.html ├── flex-images.css ├── flex-images.js ├── flex-images.min.js ├── images ├── 1.jpg ├── 10.jpg ├── 11.jpg ├── 12.jpg ├── 13.jpg ├── 14.jpg ├── 15.jpg ├── 2.jpg ├── 3.jpg ├── 4.jpg ├── 5.jpg ├── 6.jpg ├── 7.jpg ├── 8.jpg └── 9.jpg ├── package.json └── readme.md /blank.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pixabay/JavaScript-flexImages/7f505442a0904168be3f49290ff54ef9a8536786/blank.gif -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "javascript-flex-images", 3 | "description": "A lightweight vanilla JavaScript plugin for creating fluid galleries as seen on Flickr and Google Images.", 4 | "version": "1.0.2", 5 | "main" : [ 6 | "flex-images.min.js", 7 | "flex-images.css" 8 | ], 9 | "homepage": "https://github.com/Pixabay/JavaScript-flexImages", 10 | "authors": [{ 11 | "name": "Simon Steinberger", 12 | "url": "https://pixabay.com/users/Simon/", 13 | "email": "simon@pixabay.com" 14 | }], 15 | "keywords": [ 16 | "images", 17 | "pictures", 18 | "photos", 19 | "videos", 20 | "responsive", 21 | "layout", 22 | "gallery", 23 | "fluid", 24 | "grid", 25 | "flexible" 26 | ], 27 | "licenses": [{ 28 | "type": "MIT", 29 | "url": "http://www.opensource.org/licenses/mit-license.php" 30 | }], 31 | "ignore": [ 32 | "bower.json", 33 | "demo.html", 34 | "readme.md" 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /demo.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 |74 | Released under the MIT License. 75 | Source on Github (changelog). 76 | Tested in Firefox, Safari, Chrome, Opera, Internet Explorer 8+. No dependencies, written in plain JavaScript. 77 |
78 |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 |120 | Include the stylesheet flex-images.css in the <head> section of your HTML document - and the JavaScript file flex-images.min.js before the closing </body> tag. 121 | flexImages accepts settings from an object of key/value pairs. 122 |
123 |new flexImages({ key1: value1, key2: value2 });
124 | 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 |Property | Default | Description |
---|---|---|
selector | string or DOM element | Required selector for container or DOM element that holds the individual images/objects. |
container | '.item' | Selector of the individual image/object containers. |
object | 'img' | Selector of the image/object inside a container. |
rowHeight | 180 | Maximum height of a row. |
maxRows | null | Maximum number of rows to display. Images/Objects exceeding this row are hidden. |
truncate | false | Hide incomplete last row of images/objects. |
HTML Markup
143 | 144 |<div class="flex-images">
145 | <div class="item" data-w="219" data-h="180"><img src="images/1.jpg"></div>
146 | <div class="item" data-w="279" data-h="180"><img src="images/2.jpg"></div>
147 | <div class="item" data-w="270" data-h="180"><img src="images/3.jpg"></div>
148 | <div class="item" data-w="270" data-h="180"><img src="images/4.jpg"></div>
149 | <div class="item" data-w="147" data-h="180"><img src="images/5.jpg"></div>
150 | <div class="item" data-w="276" data-h="180"><img src="images/6.jpg"></div>
151 | <div class="item" data-w="319" data-h="180"><img src="images/7.jpg"></div>
152 | <div class="item" data-w="270" data-h="180"><img src="images/8.jpg"></div>
153 | <div class="item" data-w="240" data-h="180"><img src="images/9.jpg"></div>
154 | <div class="item" data-w="270" data-h="180"><img src="images/10.jpg"></div>
155 | <div class="item" data-w="240" data-h="180"><img src="images/11.jpg"></div>
156 | <div class="item" data-w="270" data-h="180"><img src="images/12.jpg"></div>
157 | <div class="item" data-w="283" data-h="180"><img src="images/13.jpg"></div>
158 | <div class="item" data-w="271" data-h="180"><img src="images/14.jpg"></div>
159 | <div class="item" data-w="258" data-h="180"><img src="images/15.jpg"></div>
160 | </div>
161 |
162 | 163 | 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. 164 |
165 |JavaScript code
166 | 167 |new flexImages({ selector: '.flex-images', rowHeight: 140 });
168 |
169 | 170 | How it works: The plugin dynamically changes the width and height of all containers. 171 | The images themselves have their height and width set to 100%. 172 | Thus, each image takes up the full space inside its container. 173 |
174 |175 | This architecture enables a very flexible grid layout that works with more than just images. 176 | 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. 177 |
178 | 179 |Please take a look at the source code of this page to see how these demos work.
181 | 182 |1. Fixed number of two complete rows with lazy loading of images; only images that are actually visible are retrieved from the server:
183 |197 | 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. 198 | On init, the plugin will replace the dummy src attribute (blank.gif) with the actual source URL for all visible images. 199 |
200 | 201 |2. A fluid grid with video content and only full rows:
202 |3. Showing a title underneath + less margin between images:
215 |4. Overlaying caption - could be a link or a button, as well:
239 |5. Cut off parts of the images, e.g. a Shutterstock ID:
263 |Original (uncut) first image with Shutterstock ID at the bottom:
286 |291 | This plugin is used in production on Pixabay.com, 292 | where you can see flexImages at work in various locations and with all available options. 293 | Please report any bugs and issues at the GitHub repositiory. 294 |
295 | 296 | 306 | 307 |This software is released as Open Source under the MIT License by Simon Steinberger / Pixabay.com.
308 |