2019-01-18 13:33:13 +00:00
|
|
|
<template>
|
2019-01-21 10:56:12 +00:00
|
|
|
<div class="background-image-loader">
|
|
|
|
<div class="background-container">
|
2019-01-22 12:54:21 +00:00
|
|
|
<div class="background background-default"
|
|
|
|
:style="backgroundDefaultStyle">
|
|
|
|
</div>
|
|
|
|
<transition name="fade">
|
|
|
|
<div class="background background-img"
|
|
|
|
:key="loadedImageUrl"
|
|
|
|
:style="backgroundStyle"
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
</transition>
|
2019-01-21 10:56:12 +00:00
|
|
|
</div>
|
2019-01-18 13:33:13 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import imageLoader from '~/mixins/imageLoader.js'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
mixins: [ imageLoader ],
|
2019-01-21 10:56:12 +00:00
|
|
|
|
2019-01-18 13:33:13 +00:00
|
|
|
props: {
|
2019-01-22 12:54:21 +00:00
|
|
|
imageUrl: {
|
2019-01-21 10:56:12 +00:00
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: function () {
|
2019-01-22 12:54:21 +00:00
|
|
|
return null
|
2019-01-21 10:56:12 +00:00
|
|
|
}
|
|
|
|
},
|
2019-01-18 13:33:13 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
data () {
|
|
|
|
return {
|
2019-01-22 12:54:21 +00:00
|
|
|
loadedImageUrl: null,
|
2019-01-18 13:33:13 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-01-21 10:56:12 +00:00
|
|
|
computed: {
|
2019-01-22 12:54:21 +00:00
|
|
|
backgroundDefaultStyle () {
|
2019-01-21 10:56:12 +00:00
|
|
|
return {
|
2019-01-22 12:54:21 +00:00
|
|
|
background: 'linear-gradient(310deg, #35405d, #6174aa, #a8b3d0, #e2e5ef)'
|
2019-01-21 10:56:12 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
backgroundStyle () {
|
2019-01-22 12:54:21 +00:00
|
|
|
let style = {}
|
|
|
|
if (this.loadedImageUrl) {
|
|
|
|
style.backgroundImage = `url(${this.loadedImageUrl})`
|
2019-01-21 10:56:12 +00:00
|
|
|
}
|
2019-01-22 12:54:21 +00:00
|
|
|
|
|
|
|
return style
|
2019-01-21 10:56:12 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-01-22 12:54:21 +00:00
|
|
|
watch: {
|
|
|
|
imageUrl () {
|
|
|
|
if (this.imageUrl) {
|
|
|
|
this.setImage(this.imageUrl)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted () {
|
|
|
|
this.setImage(this.imageUrl)
|
|
|
|
},
|
|
|
|
|
2019-01-18 13:33:13 +00:00
|
|
|
methods: {
|
2019-01-22 12:54:21 +00:00
|
|
|
setImage(url) {
|
|
|
|
if (url === null) { return }
|
|
|
|
this.loadImage(url)
|
|
|
|
.then(img => {
|
|
|
|
this.loadedImageUrl = img.src
|
|
|
|
this.$emit('imageLoaded', img)
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
this.$emit('imageLoadError', err)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
2019-01-18 13:33:13 +00:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
2019-01-21 10:56:12 +00:00
|
|
|
.background-image-loader {
|
|
|
|
position: relative;
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.background {
|
2019-01-18 13:33:13 +00:00
|
|
|
position: absolute;
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
top: 0;
|
2019-01-21 10:56:12 +00:00
|
|
|
left: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.background-img {
|
|
|
|
background-size: cover;
|
|
|
|
background-position: center center;
|
2019-01-22 12:54:21 +00:00
|
|
|
opacity: 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
.fade {
|
|
|
|
&-enter-active {
|
|
|
|
transition: opacity 2s 1s;
|
|
|
|
}
|
|
|
|
|
|
|
|
&-leave-active {
|
|
|
|
transition: opacity 3s;
|
|
|
|
}
|
|
|
|
|
|
|
|
&-enter, &-leave-to {
|
|
|
|
opacity: 0;
|
|
|
|
}
|
2019-01-18 13:33:13 +00:00
|
|
|
}
|
|
|
|
</style>
|