Skip to content

Commit 758e187

Browse files
committed
Added loader
1 parent 890c6f7 commit 758e187

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

src/Components/Lightbox.vue

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
</svg>
1818
</div>
1919
<div class="lightbox__image" @click.stop="">
20-
<img :src="images[index]">
20+
<slot name="loader" v-if="$slots.loader"></slot>
21+
<img :src="images[index]" @load="loaded" v-if="displayImage">
2122
</div>
2223
<div
2324
class="lightbox__arrow lightbox__arrow--right"
@@ -35,6 +36,8 @@
3536
</template>
3637

3738
<script>
39+
import Vue from 'vue'
40+
3841
export default {
3942
props: [
4043
'thumbnail',
@@ -45,6 +48,7 @@
4548
return {
4649
visible: false,
4750
index: 0,
51+
displayImage: true,
4852
}
4953
},
5054
mounted() {
@@ -71,13 +75,22 @@
7175
prev() {
7276
if (this.has_prev()) {
7377
this.index -= 1
78+
this.tick()
7479
}
7580
},
7681
next() {
7782
if (this.has_next()) {
7883
this.index += 1
84+
this.tick()
7985
}
8086
},
87+
tick() {
88+
this.displayImage = false
89+
90+
Vue.nextTick(() => {
91+
this.displayImage = true
92+
})
93+
},
8194
eventListener(e) {
8295
if (this.visible) {
8396
switch (e.key) {
@@ -163,6 +176,7 @@
163176
.lightbox__image {
164177
flex: 1;
165178
}
179+
166180
.lightbox__image img {
167181
width: 100%;
168182
height: auto !important;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<template>
2+
<div class="lightbox__default-loader">
3+
<div class="lightbox__default-loader__element"></div>
4+
</div>
5+
</template>
6+
7+
<script>
8+
export default {
9+
//
10+
}
11+
</script>
12+
13+
<style>
14+
.lightbox__default-loader {
15+
position: absolute;
16+
top: 50%;
17+
left: 50%;
18+
transform: translate(-50%, -50%);
19+
z-index: -1;
20+
}
21+
22+
.lightbox__default-loader__element {
23+
animation: LightboxDefaultLoaderAnimation 1s linear infinite;
24+
border: 3px solid #292929;
25+
border-top: 3px solid #fff;
26+
border-radius: 50%;
27+
height: 75px;
28+
width: 75px;
29+
}
30+
31+
@keyframes LightboxDefaultLoaderAnimation {
32+
to {
33+
border-top-color: #fff;
34+
transform: rotate(360deg);
35+
}
36+
}
37+
</style>

src/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import LightboxComponent from './Components/Lightbox.vue'
2+
import LightboxDefaultLoader from './Components/LightboxDefaultLoader.vue'
23

34
const Lightbox = {
45
install(Vue, options = {}) {
56
Vue.mixin({
67
components: {
78
lightbox: LightboxComponent,
9+
LightboxDefaultLoader,
810
},
911
});
1012
},

0 commit comments

Comments
 (0)