Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the closeOnScroll option. #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,6 @@ Options that could be specified in directive value
| closed | Function that will be executed on gallery close | undefined | function |
| changed(imageIndex) | Function that will be executed when switching between images in gallery | undefined | function |
| cursor | Cursor when hovering original `<img>` | 'pointer' | string |
| closeOnScroll | Determines if the gallery should close upon scrolling. NOTE: If this option is set to false, the page will not scroll when the gallery is open. | true | boolean |

* Any of these options except `opened`, `closed`, `changed` functions and `openOn` property could be changed at runtime.
220 changes: 219 additions & 1 deletion dist/v-img.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/v-img.js.map

Large diffs are not rendered by default.

212 changes: 211 additions & 1 deletion dist/v-img.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/v-img.mjs.map

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion lib/ImgScreen.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,22 @@ export default {
uiTimeout: null,
handlers: {},
thumbnails: false,
closeOnScroll: false,
};
},
watch: {
closed(newVal) {
// Disable scrolling when the gallery is visible and the
// closeOnScroll option is false.
if(!this.closeOnScroll) {
if (this.closed) {
document.documentElement.style.overflow = 'auto';
}
else {
document.documentElement.style.overflow = 'hidden';
}
}

if (newVal && this.handlers.closed) {
this.handlers.closed();
}
Expand Down Expand Up @@ -159,7 +171,9 @@ export default {
if (e.keyCode === 37 || e.keyCode === 72) this.prev();
});
window.addEventListener('scroll', () => {
this.close();
if (this.closeOnScroll) {
this.close();
}
});
window.addEventListener('mousemove', () => {
this.showUI();
Expand Down
9 changes: 9 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const addPluginAttributes = (el, binding, options) => {
let src = el.src; // eslint-disable-line prefer-destructuring
let title;
let thumbnails;
let closeOnScroll;
const events = {};

if (options.altAsTitle) title = el.alt;
Expand All @@ -21,6 +22,7 @@ const addPluginAttributes = (el, binding, options) => {
openOn = options.openOn;
sourceButton = options.sourceButton;
thumbnails = options.thumbnails;
closeOnScroll = options.closeOnScroll;
/* eslint-enable prefer-destructuring */

// Overriding options if they're provided in binding.value
Expand All @@ -44,6 +46,10 @@ const addPluginAttributes = (el, binding, options) => {
if (binding.value.thumbnails !== undefined) {
thumbnails = binding.value.thumbnails; // eslint-disable-line prefer-destructuring
}
// same as above
if (binding.value.closeOnScroll !== undefined) {
closeOnScroll = binding.value.closeOnScroll; // eslint-disable-line prefer-destructuring
}
}

// Setting up data attributes for dynamic properties
Expand All @@ -68,6 +74,7 @@ const addPluginAttributes = (el, binding, options) => {
sourceButton,
openOn,
thumbnails,
closeOnScroll,
};
};

Expand All @@ -79,6 +86,7 @@ const install = (Vue, options) => {
sourceButton: false,
thumbnails: false,
openOn: 'click',
closeOnScroll: true,
};

// eslint-disable-next-line no-param-reassign
Expand Down Expand Up @@ -136,6 +144,7 @@ const install = (Vue, options) => {
Vue.set(vm, 'currentImageIndex', images.indexOf(el));
Vue.set(vm, 'handlers', addedAttributes.events);
Vue.set(vm, 'closed', false);
Vue.set(vm, 'closeOnScroll', addedAttributes.closeOnScroll);
});
},
});
Expand Down
Loading