-
Notifications
You must be signed in to change notification settings - Fork 238
Description
I'm using Vue.js in a project where I have a scroll container and its child elements.
In the scroll container:
mounted: function () {
this.monitor = scrollMonitor.createContainer(this.$el);
},
updated: function () {
this.monitor.recalculateLocations();
}
In the child elements:
mounted () {
this.watcher = this.monitor.create(this.$el);
this.inViewport = this.watcher.isInViewport;
this.watcher.visibilityChange(() => {
this.inViewport = this.watcher.isInViewport;
});
},
beforeDestroy () {
this.watcher.destroy();
}
The scroll container passes the scroll monitor to its children through a Vue property.
This works perfectly fine, until an element is moved from one position in the list to another. This is causing the associated DOM element to be moved in the scroll container, and the updated Hook function is called. This Hook function invokes monitor.recalculateLocations() to have the children watchers recalculate their locations and triggers events. But this is not happening (if the element is moved from a position where it is not visible to a position where it is visible in the scroll container, no event is fired), and I would like to understand why.
Example:
- Div for element 1 (in viewport)
- Div for element 2 (in viewport)
- etc.
- Div for element n (not in viewport)
The element n is moved to top, resulting in the following changes in the DOM:
- Div for element n (in viewport)
- Div for element 1 (in viewport)
- etc.
- Div for element n-1 (not in viewport)
The Div for element n is now visible in it's parent scroll container. However, when the scrollMonitor.recalculateLocations() is called, the watcher created for element n does not trigger the visibility change callback.