Callback when plugin finish painting elements #62
Replies: 4 comments 4 replies
-
There is a custom Vue event |
Beta Was this translation helpful? Give feedback.
-
Thank you @DerYeger for this precision. I am not sure but is it possible to listen for this event ? I tried this without sucess onMounted(() => {
document
.querySelector<HTMLDivElement>('#masonry-gallery')
.addEventListener('redraw', () => {
console.log('redraw') // not displayed
})
}) |
Beta Was this translation helpful? Give feedback.
-
Thank you @DerYeger ! I checked the doc and it is working. However, not sure that the event is emitted at right time. I am trying to call a refresh function but I still need to put 100ms delay after redraw event to make it work. see <script setup lang="ts">
const delay100 = delay(100)
const onRedraw = () => {
delay100.then(() => {
ScrollTrigger.refresh()
})
}
</script>
<template>
<MasonryWall @redraw="onRedraw"></MasonryWall>
</template> // utils.ts
export const delay = (n: number) => {
n = n || 2000
return new Promise<void>((resolve) => {
setTimeout(() => {
resolve()
}, n)
})
} |
Beta Was this translation helpful? Give feedback.
-
@DerYeger thanks ! By any means do you know what's the correct syntax for Unhandled Promise Rejection: TypeError: undefined is not an object (evaluating 'this.$nextTick') Here is my code <script setup lang="ts">
async function onRedraw() {
await this.$nextTick()
ScrollTrigger.refresh()
}
</script>
<template>
<MasonryWall @redraw="onRedraw"></MasonryWall>
</template> |
Beta Was this translation helpful? Give feedback.
-
Hello,
I don't think this feature already exists on this plugin so I would like to share my idea as I think it can be useful in some situations.
It could be great to add eventListeners to this plugin like when all elements are displayed.
My use case : I am adding items by assigning a new value to the items property (with an API refresh call) when the user is clicking on a button. I can create a callback after my API is refreshed and items has a new value but I'd like to wait until the plugin processed the data and display them to the dom (which can take 50 to 300ms depending on the quantity of items that are added to the dom)
Beta Was this translation helpful? Give feedback.
All reactions