primevue-mirror/apps/showcase/components/demo/DeferredDemo.vue

79 lines
1.7 KiB
Vue
Raw Normal View History

2023-12-31 14:08:33 +00:00
<template>
2024-01-12 11:24:12 +00:00
<div v-if="!visible">
<div class="card">
<div class="deferred-demo-loading"></div>
</div>
</div>
2023-12-31 14:08:33 +00:00
<slot v-else></slot>
</template>
<script>
export default {
name: 'DeferredDemo',
emits: ['load'],
props: {
options: {
type: Object,
default: null
}
},
data() {
return {
visible: false
};
},
observer: null,
timeout: null,
mounted() {
this.observer = new IntersectionObserver(([entry]) => {
clearTimeout(this.timeout);
if (entry.isIntersecting) {
this.timeout = setTimeout(() => {
this.visible = true;
this.observer.unobserve(this.$el);
this.$emit('load');
}, 350);
}
}, this.options);
this.observer.observe(this.$el);
},
beforeUnmount() {
!this.visible && this.$el && this.observer?.unobserve(this.$el);
clearTimeout(this.timeout);
}
};
</script>
<style>
2024-01-12 11:24:12 +00:00
.deferred-demo-loading {
2023-12-31 14:08:33 +00:00
border-radius: 10px;
height: 350px;
2024-01-12 11:24:12 +00:00
position: relative;
overflow: hidden;
}
.deferred-demo-loading::after {
content: '';
animation: deferred-demo-loading 1.2s infinite;
left: 0;
position: absolute;
right: 0;
top: 0;
height: 100%;
transform: translateX(-100%);
z-index: 1;
border-radius: 10px;
2024-03-26 15:38:53 +00:00
background: linear-gradient(90deg, rgba(255, 255, 255, 0), var(--hover-background), rgba(255, 255, 255, 0));
2024-01-12 11:24:12 +00:00
}
@keyframes deferred-demo-loading {
from {
transform: translateX(-100%);
}
to {
transform: translateX(100%);
}
2023-12-31 14:08:33 +00:00
}
</style>