
let lazyPlugin: any = {}

lazyPlugin.install = (app: any) => {
  app.directive('lazy-load', {
    mounted(el: any, binding: any) {
      let io = new IntersectionObserver(entries => {
        entries.forEach(entry => {
          let lazyImage: any = entry.target;
          if (entry.intersectionRatio > 0) {
            lazyImage.src = binding.value;
            io.unobserve(lazyImage);
          }
        });
      });
      io.observe(el);
    }
  })
}

export default lazyPlugin