Last active
September 1, 2017 15:02
-
-
Save raae/72b4ccc207214b1c84d8e0e1fd341aa3 to your computer and use it in GitHub Desktop.
Super simple vue snippet for lazy loading images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<transition name="fade"> | |
<img v-if="imageSrc" :src="imageSrc" /> | |
</transition> | |
</template> | |
<script> | |
export default { | |
props: [ | |
'src' | |
], | |
data() { | |
return { | |
imageSrc: null | |
} | |
}, | |
mounted() { | |
let image = new Image() | |
image.src = this.src | |
image.onload = () => { | |
this.imageSrc = this.src | |
} | |
} | |
} | |
</script> | |
<style lang="scss" scoped> | |
.fade-enter-active, | |
.fade-leave-active { | |
transition: all 250ms ease-in-out; | |
} | |
.fade-enter, | |
.fade-leave-to { | |
opacity: 0; | |
transform: scale(0.95); | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment