UNPKG

11.1 kBMarkdownView Raw
1<p align="center">
2<img src="https://cdn.rawgit.com/RobinCK/vue-gallery/a08dae25/doc/gallery.png">
3</p>
4
5<p align="center">
6 <a href="https://opencollective.com/vue-gallery" alt="Financial Contributors on Open Collective"><img src="https://opencollective.com/vue-gallery/all/badge.svg?label=financial+contributors" /></a>
7 <a href="https://github.com/RobinCK/vue-gallery"><img src="https://img.shields.io/badge/vuejs-2.x-brightgreen.svg?style=flat-square"></a>
8 <a href="https://www.npmjs.com/package/vue-gallery"><img src="https://img.shields.io/npm/dt/vue-gallery.svg?style=flat-square"></a>
9</p>
10
11<p align="center">
12 <a href="https://david-dm.org/RobinCK/vue-gallery"><img src="https://david-dm.org/RobinCK/vue-gallery.svg?style=flat-square"></a>
13 <a href="https://david-dm.org/RobinCK/vue-gallery?type=dev"><img src="https://david-dm.org/RobinCK/vue-gallery/dev-status.svg?style=flat-square"></a>
14 <a href="https://github.com/RobinCK/vue-gallery"><img src="https://img.shields.io/npm/v/vue-gallery.svg?style=flat-square"></a>
15 <a href="https://github.com/RobinCK/vue-gallery/blob/master/LICENSE"><img src="https://img.shields.io/npm/l/vue-gallery.svg?style=flat-square"></a>
16
17</p>
18
19# vue-gallery
20
21[![Greenkeeper badge](https://badges.greenkeeper.io/RobinCK/vue-gallery.svg)](https://greenkeeper.io/)
22:camera: VueJS responsive and customizable image and video gallery, carousel and lightbox, optimized for both mobile and desktop web browsers.
23
24## Example
25
26[jsFiddle - image](https://fiddle.jshell.net/Robin_ck/LffrLb2k/show/light/)
27
28[jsFiddle - video](https://fiddle.jshell.net/Robin_ck/djqcrm8m/show/light/)
29
30## Install
31#### CDN
32
33Recommended: https://unpkg.com/vue-gallery, which will reflect the latest version as soon as it is published to npm. You can also browse the source of the npm package at https://unpkg.com/vue-gallery/
34
35#### npm
36
37``` bash
38npm install vue-gallery
39
40```
41
42#### Yarn
43
44``` bash
45yarn add vue-gallery
46
47```
48
49### Nuxt
50
511. Add a new file named `vue-gallery.client.js` to your nuxt plugins folder. It is important that your filename ends in `.client.js` ([more info on this convention](https://nuxtjs.org/guide/plugins/#name-conventional-plugin), only works from Nuxt v.2.4.0).
522. Copy paste the following content in it:
53```js
54import Vue from 'vue'
55import VueGallery from 'vue-gallery'
56
57Vue.component('VGallery', VueGallery)
58```
593. Add it to your list of plugins in `nuxt.config.js`:
60```js
61plugins: ['~plugins/vue-gallery.client.js']
62```
634. You can now use the component globally:
64```js
65<v-gallery :images="images"
66 :index="index"
67 @close="index = null" />
68```
69
70## Usage
71
72### VueJS single file (ECMAScript 2015)
73```html
74<template>
75 <div>
76 <gallery :images="images" :index="index" @close="index = null"></gallery>
77 <div
78 class="image"
79 v-for="(image, imageIndex) in images"
80 :key="imageIndex"
81 @click="index = imageIndex"
82 :style="{ backgroundImage: 'url(' + image + ')', width: '300px', height: '200px' }"
83 ></div>
84 </div>
85</template>
86
87<script>
88 import VueGallery from 'vue-gallery';
89
90 export default {
91 data: function () {
92 return {
93 images: [
94 'https://dummyimage.com/800/ffffff/000000',
95 'https://dummyimage.com/1600/ffffff/000000',
96 'https://dummyimage.com/1280/000000/ffffff',
97 'https://dummyimage.com/400/000000/ffffff',
98 ],
99 index: null
100 };
101 },
102
103 components: {
104 'gallery': VueGallery
105 },
106 }
107</script>
108
109<style scoped>
110 .image {
111 float: left;
112 background-size: cover;
113 background-repeat: no-repeat;
114 background-position: center center;
115 border: 1px solid #ebebeb;
116 margin: 5px;
117 }
118</style>
119
120```
121
122### Browser (ES5)
123```html
124 <script type="text/javascript" src="https://unpkg.com/vue@2.4.3/dist/vue.js"></script>
125 <script type="text/javascript" src="https://unpkg.com/blueimp-gallery@2.27.0/js/blueimp-helper.js"></script>
126 <script type="text/javascript" src="https://unpkg.com/blueimp-gallery@2.27.0/js/blueimp-gallery.js"></script>
127 <script type="text/javascript" src="https://unpkg.com/blueimp-gallery@2.27.0/js/blueimp-gallery-fullscreen.js"></script>
128 <script type="text/javascript" src="vue-gallery.js"></script>
129 <link rel="stylesheet" type="text/css" href="https://unpkg.com/blueimp-gallery@2.27.0/css/blueimp-gallery.min.css">
130
131
132<div id="app">
133 <gallery :images="images" :index="index" @close="index = null"></gallery>
134 <div
135 class="image"
136 v-for="image, imageIndex in images"
137 @click="index = imageIndex"
138 :style="{ backgroundImage: 'url(' + image + ')', width: '300px', height: '200px' }"
139 ></div>
140</div>
141
142<script type="text/javascript">
143 new Vue({
144 el: '#app',
145 data: function () {
146 return {
147 images: [
148 'https://dummyimage.com/800/ffffff/000000',
149 'https://dummyimage.com/1600/ffffff/000000',
150 'https://dummyimage.com/1280/000000/ffffff',
151 'https://dummyimage.com/400/000000/ffffff'
152 ],
153 index: null
154 };
155 },
156
157 components: {
158 'gallery': VueGallery
159 }
160 });
161</script>
162```
163
164## Props
165
166| Props | Type | Default | Description |
167| --------------------|:----------| ------------------------------------------------|--------------|
168| images | Array | [] | Urls list |
169| index | Number | null | Opened image index |
170| options | Object | | [blueimp-gallery](https://github.com/blueimp/Gallery) options |
171
172
173
174## Events
175| Name | Params | Description |
176| -----------------|:------------------------|--------------|
177| onopen | | |
178| onopened | | |
179| onslide | | |
180| onslideend | | |
181| onslidecomplete | | |
182| onclose | | |
183| onclosed | | |
184
185
186## Known Issues
187
188### 1. Multiple VueGallery components in same page breaks functionalities
189
190**Fix:** Give each gallery a unique id. [jsFiddle Example](https://jsfiddle.net/sam_saama/nzjp13ec/)
191
192### 2. Images not oriented correctly.
193
194It's because the image isn't in the "correct" orientation and the exif orientation data is what "fixes" the orientation when you view the images. Browsers don't fix the image orientation based on the exif data. Some browsers show it "correctly" when you open the image in a new tab by itself but don't fix it if you use the image link in a src attribute. [Relevant stackoverflow](https://stackoverflow.com/questions/24658365/img-tag-displays-wrong-orientation).
195
196**Fix:** Use the `onslide` callback to read the exif data and "correct" the orientation based of the exif orientation. [More info on blueimp-gallery](https://github.com/blueimp/Gallery#event-callbacks).
197
198[jsFiddle Example](https://jsfiddle.net/sam_saama/72k0xr3n/)
199
200Code excerpt:
201
202```html
203<gallery :options="options" :images="images" :index="index" @close="index = null"/>
204```
205
206```js
207data() {
208 //...
209 options: {
210 onslide: function(index, slide) {
211 const rotation = {
212 1: 'rotate(0deg)',
213 3: 'rotate(180deg)',
214 6: 'rotate(90deg)',
215 8: 'rotate(270deg)'
216 }
217
218 //Conditionally change rotation of image based on the image orientation data. Example jsfiddle --> https://jsfiddle.net/orotemo/obvna6qn/ Or use something like https://github.com/mattiasw/ExifReader
219 //But for this example, the fix has been hardcoded.
220 slide.getElementsByTagName(
221 'img'
222 )[0].style = `transform: ${rotation['3']};`
223 }
224 }
225}
226
227```
228
229## Other my Vue JS plugins
230
231| Project | Status | Description |
232|---------|--------|-------------|
233| [vue-ls](https://github.com/RobinCK/vue-ls) | ![npm](https://img.shields.io/npm/v/vue-ls.svg) | Vue plugin for work with local storage, session storage and memory storage from Vue context |
234| [vue-popper](https://github.com/RobinCK/vue-popper) | ![npm](https://img.shields.io/npm/v/vue-popperjs.svg) | VueJS popover component based on <a href="https://popper.js.org/">popper.js</a> |
235
236
237## Development Setup
238
239``` bash
240# install dependencies
241npm install
242
243# build dist files
244npm run build
245```
246
247## Contributors
248
249### Code Contributors
250
251This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
252<a href="https://github.com/RobinCK/vue-gallery/graphs/contributors"><img src="https://opencollective.com/vue-gallery/contributors.svg?width=890&button=false" /></a>
253
254### Financial Contributors
255
256Become a financial contributor and help us sustain our community. [[Contribute](https://opencollective.com/vue-gallery/contribute)]
257
258#### Individuals
259
260<a href="https://opencollective.com/vue-gallery"><img src="https://opencollective.com/vue-gallery/individuals.svg?width=890"></a>
261
262#### Organizations
263
264Support this project with your organization. Your logo will show up here with a link to your website. [[Contribute](https://opencollective.com/vue-gallery/contribute)]
265
266<a href="https://opencollective.com/vue-gallery/organization/0/website"><img src="https://opencollective.com/vue-gallery/organization/0/avatar.svg"></a>
267<a href="https://opencollective.com/vue-gallery/organization/1/website"><img src="https://opencollective.com/vue-gallery/organization/1/avatar.svg"></a>
268<a href="https://opencollective.com/vue-gallery/organization/2/website"><img src="https://opencollective.com/vue-gallery/organization/2/avatar.svg"></a>
269<a href="https://opencollective.com/vue-gallery/organization/3/website"><img src="https://opencollective.com/vue-gallery/organization/3/avatar.svg"></a>
270<a href="https://opencollective.com/vue-gallery/organization/4/website"><img src="https://opencollective.com/vue-gallery/organization/4/avatar.svg"></a>
271<a href="https://opencollective.com/vue-gallery/organization/5/website"><img src="https://opencollective.com/vue-gallery/organization/5/avatar.svg"></a>
272<a href="https://opencollective.com/vue-gallery/organization/6/website"><img src="https://opencollective.com/vue-gallery/organization/6/avatar.svg"></a>
273<a href="https://opencollective.com/vue-gallery/organization/7/website"><img src="https://opencollective.com/vue-gallery/organization/7/avatar.svg"></a>
274<a href="https://opencollective.com/vue-gallery/organization/8/website"><img src="https://opencollective.com/vue-gallery/organization/8/avatar.svg"></a>
275<a href="https://opencollective.com/vue-gallery/organization/9/website"><img src="https://opencollective.com/vue-gallery/organization/9/avatar.svg"></a>
276
277## License
278[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2FRobinCK%2Fvue-gallery.svg?type=large)](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2FRobinCK%2Fvue-gallery?ref=badge_large)
279
280MIT © [Igor Ognichenko](https://github.com/RobinCK)