Skip to content

Commit d220fc6

Browse files
authored
Merge pull request #33 from jstr14/master
Disable Scroll html
2 parents 26f3ee3 + 1d49816 commit d220fc6

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

src/components/script.js

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@ export default {
44
props: {
55
open: {
66
type: Boolean,
7-
default: false
7+
default: false,
88
},
9-
9+
1010
images: {
1111
type: Array,
1212
required: true,
1313
},
1414

15+
disableScroll: {
16+
type: Boolean,
17+
default: true,
18+
},
19+
1520
showLightBox: {
1621
type: Boolean,
1722
default: true,
@@ -34,7 +39,7 @@ export default {
3439

3540
// Mode
3641
autoPlay: {
37-
type: Boolean,
42+
type: Boolean,
3843
default: false,
3944
},
4045

@@ -60,26 +65,25 @@ export default {
6065
lightBoxOn: this.showLightBox,
6166
displayThumbs: this.images.slice(0, this.nThumbs),
6267
timer: null,
63-
6468
beginThumbIndex: 0,
6569
}
6670
},
6771

6872
computed: {
69-
countImages() {
73+
countImages () {
7074
return this.images.length
7175
},
7276

73-
imagesThumb() {
77+
imagesThumb () {
7478
if (this.siteLoading) {
75-
return this.displayThumbs.map(({ thumb }) => ({
79+
return this.displayThumbs.map(({thumb}) => ({
7680
src: thumb,
7781
loading: this.siteLoading,
78-
error: this.siteLoading,
82+
error: this.siteLoading
7983
}))
8084
}
8185

82-
return this.displayThumbs.map(({ thumb }) => thumb)
86+
return this.displayThumbs.map(({thumb}) => thumb)
8387
},
8488
},
8589

@@ -119,19 +123,25 @@ export default {
119123
lightBoxOn(value) {
120124
if (document != null) {
121125
if (value) {
126+
if (this.disableScroll) {
127+
document.getElementsByTagName('html')[0].classList.add('no-scroll')
128+
}
122129
document.getElementsByTagName('body')[0].classList.add('vue-lb-open')
123130
this.$emit('lightBoxOn', true)
124131
} else {
132+
if (this.disableScroll) {
133+
document.getElementsByTagName('html')[0].classList.remove('no-scroll')
134+
}
125135
document.getElementsByTagName('body')[0].classList.remove('vue-lb-open')
126136
this.$emit('lightBoxOn', false)
127137
}
128-
}
138+
}
129139
},
130-
140+
131141
open(value) {
132142
if (value) {
133-
this.openLightBox();
134-
this.$emit('opened');
143+
this.openLightBox()
144+
this.$emit('opened')
135145
}
136146
},
137147
},
@@ -147,7 +157,6 @@ export default {
147157
methods: {
148158
showImage(index) {
149159
document.addEventListener('keydown', this.addKeyEvent)
150-
151160
this.$set(this, 'lightBoxOn', true)
152161
this.$set(this, 'select', index)
153162
},
@@ -162,9 +171,9 @@ export default {
162171
this.$set(this, 'lightBoxOn', false)
163172
document.removeEventListener('keydown', this.addKeyEvent)
164173
},
165-
174+
166175
openLightBox() {
167-
this.showImage(this.beginThumbIndex);
176+
this.showImage(this.beginThumbIndex)
168177
},
169178

170179
nextImage() {
@@ -176,7 +185,6 @@ export default {
176185
},
177186
},
178187

179-
180188
beforeDestroy() {
181189
document.removeEventListener('keydown', this.addKeyEvent)
182190

src/components/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,7 @@ img.vue-lb-modal-image {
256256
.fade-enter, .fade-leave-to {
257257
opacity: 0;
258258
}
259+
260+
.no-scroll {
261+
overflow-y: hidden;
262+
}

0 commit comments

Comments
 (0)