Last active
April 22, 2018 01:22
-
-
Save alfari16/4d966af1a802cd971797d4fc9bc2800c to your computer and use it in GitHub Desktop.
This file contains hidden or 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> | |
| <div ref="imgComponent"> | |
| <img v-if="check" :src="dataSrc" :alt="dataAlt" class="thumbnail"> | |
| <div class="loading loading-img" v-else></div> <!-- Placeholder yang sama dengan saat pertama kali load --> | |
| </div> | |
| </template> | |
| <script> | |
| export default { | |
| data() { | |
| return { | |
| check: false //Menyembunyikan gambar | |
| }; | |
| }, | |
| props: ["data-src", "data-alt"], | |
| mounted(){ | |
| let scroll = pageYOffset+outerHeight | |
| const position = this.$refs.imgComponent.getBoundingClientRect().top | |
| window.addEventListener('scroll',()=>{ | |
| scroll = pageYOffset+outerHeight | |
| if(position<=scroll) this.check=true //memuat gambar ketika DOM sudah termuat secara sempurna | |
| }) | |
| if(position<=scroll) this.check=true //memuat gambar ketika DOM sudah termuat secara sempurna | |
| } | |
| }; | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment