mirror of
https://github.com/primefaces/primevue.git
synced 2025-05-09 17:02:38 +00:00
Styles imported. Components added
This commit is contained in:
parent
3cb3910561
commit
8264983db4
452 changed files with 55902 additions and 0 deletions
62
components/deferredcontent/DeferredContent.vue
Executable file
62
components/deferredcontent/DeferredContent.vue
Executable file
|
@ -0,0 +1,62 @@
|
|||
<template>
|
||||
<div ref="container">
|
||||
<slot v-if="loaded"></slot>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'DeferredContent',
|
||||
emits: ['load'],
|
||||
data() {
|
||||
return {
|
||||
loaded: false
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
if (!this.loaded) {
|
||||
if (this.shouldLoad())
|
||||
this.load();
|
||||
else
|
||||
this.bindScrollListener();
|
||||
}
|
||||
},
|
||||
beforeUnmount() {
|
||||
this.unbindScrollListener();
|
||||
},
|
||||
methods: {
|
||||
bindScrollListener() {
|
||||
this.documentScrollListener = () => {
|
||||
if (this.shouldLoad()) {
|
||||
this.load();
|
||||
this.unbindScrollListener();
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener('scroll', this.documentScrollListener);
|
||||
},
|
||||
unbindScrollListener() {
|
||||
if (this.documentScrollListener) {
|
||||
window.removeEventListener('scroll', this.documentScrollListener);
|
||||
this.documentScrollListener = null;
|
||||
}
|
||||
},
|
||||
shouldLoad() {
|
||||
if (this.loaded) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
const rect = this.$refs.container.getBoundingClientRect();
|
||||
const docElement = document.documentElement;
|
||||
const winHeight = docElement.clientHeight;
|
||||
|
||||
return (winHeight >= rect.top);
|
||||
}
|
||||
},
|
||||
load(event) {
|
||||
this.loaded = true;
|
||||
this.$emit('load', event);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue