How would I pass an extra argument to the IntersectionObserver? I am trying to create a lazyload plugin for Vue. It works fine like this but I also want to be able to call a provided directive function.
const lazyload = {
install(Vue) {
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.intersectionRatio > 0) {
console.log('In viewport');
}
});
});
Vue.directive('lazy', {
inserted(element) {
observer.observe(element);
}
});
}
};
This would mean that in the inserted function I would set binding
as the second argument.
inserted(element, binding)
How would I pass this binding though so that I could use it within my IntersectionObserver callback?
In the end it should be able to look something like this:
<div class="col-sm-6" v-lazy="fire">