Skip to content

Commit

Permalink
Added loader
Browse files Browse the repository at this point in the history
  • Loading branch information
DCzajkowski committed Jul 29, 2018
1 parent 890c6f7 commit 758e187
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Components/Lightbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
</svg>
</div>
<div class="lightbox__image" @click.stop="">
<img :src="images[index]">
<slot name="loader" v-if="$slots.loader"></slot>
<img :src="images[index]" @load="loaded" v-if="displayImage">
</div>
<div
class="lightbox__arrow lightbox__arrow--right"
Expand All @@ -35,6 +36,8 @@
</template>

<script>
import Vue from 'vue'
export default {
props: [
'thumbnail',
Expand All @@ -45,6 +48,7 @@
return {
visible: false,
index: 0,
displayImage: true,
}
},
mounted() {
Expand All @@ -71,13 +75,22 @@
prev() {
if (this.has_prev()) {
this.index -= 1
this.tick()
}
},
next() {
if (this.has_next()) {
this.index += 1
this.tick()
}
},
tick() {
this.displayImage = false
Vue.nextTick(() => {
this.displayImage = true
})
},
eventListener(e) {
if (this.visible) {
switch (e.key) {
Expand Down Expand Up @@ -163,6 +176,7 @@
.lightbox__image {
flex: 1;
}
.lightbox__image img {
width: 100%;
height: auto !important;
Expand Down
37 changes: 37 additions & 0 deletions src/Components/LightboxDefaultLoader.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<template>
<div class="lightbox__default-loader">
<div class="lightbox__default-loader__element"></div>
</div>
</template>

<script>
export default {
//
}
</script>

<style>
.lightbox__default-loader {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: -1;
}
.lightbox__default-loader__element {
animation: LightboxDefaultLoaderAnimation 1s linear infinite;
border: 3px solid #292929;
border-top: 3px solid #fff;
border-radius: 50%;
height: 75px;
width: 75px;
}
@keyframes LightboxDefaultLoaderAnimation {
to {
border-top-color: #fff;
transform: rotate(360deg);
}
}
</style>
2 changes: 2 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import LightboxComponent from './Components/Lightbox.vue'
import LightboxDefaultLoader from './Components/LightboxDefaultLoader.vue'

const Lightbox = {
install(Vue, options = {}) {
Vue.mixin({
components: {
lightbox: LightboxComponent,
LightboxDefaultLoader,
},
});
},
Expand Down

0 comments on commit 758e187

Please sign in to comment.