-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLazyImage.vue
36 lines (35 loc) · 835 Bytes
/
LazyImage.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<template>
<span class=“relative-position” :class="spanClass" v-intersection.once="onIntersection">
<transition name="q-transition--scale">
<img
v-show="loaded && intersect"
@load="loaded=true"
:src="intersect ? src : '/'"
:title="title"
:alt="title"
:class="imgClass"
:style="(loaded && intersect) ? imgStyle : ''" />
</transition>
</span>
</template>
<script>
export default {
name: 'LazyImg',
props: ['title', 'imgStyle', 'src', 'srclazy', 'imgClass', 'spanClass'],
data () {
return {
loaded: false,
intersect: false
}
},
methods: {
onIntersection (entry) {
if (entry.isIntersecting) {
this.loaded = false
this.intersect = true
}
}
}
}
</script>
<style lang=“sass” scoped></style>