load demo only when in viewport

This commit is contained in:
Philipp Kühn
2021-03-19 17:01:36 +01:00
parent 72c17f9dde
commit 7a20640872
3 changed files with 26 additions and 1 deletions

View File

@@ -1,5 +1,12 @@
<template>
<div class="demo-frame" :class="{ 'is-inline': inline, 'is-loading': isLoading }">
<div
class="demo-frame"
:class="{ 'is-inline': inline, 'is-loading': isLoading }"
v-observe-visibility="{
callback: visibilityChanged,
once: true,
}"
>
<div class="demo-frame__loader-wrapper" v-if="isLoading">
<div class="demo-frame__loader" />
</div>
@@ -11,11 +18,14 @@
height="0"
frameborder="0"
@load="onLoad"
v-if="isVisible"
/>
</div>
</template>
<script>
import { ObserveVisibility } from 'vue-observe-visibility'
export default {
props: {
name: {
@@ -39,9 +49,14 @@ export default {
},
},
directives: {
ObserveVisibility,
},
data() {
return {
isLoading: true,
isVisible: false,
}
},
@@ -55,6 +70,10 @@ export default {
onLoad() {
this.isLoading = false
},
visibilityChanged(isVisible) {
this.isVisible = isVisible
},
},
}
</script>